Can't Remove Public ADO Connection

Feb 12, 2009

I have a VBA application that uses data from a sheet in the excel workbook. It accesses this data with an ADO connection. On workbook open I open this connection--I declare it as public variable so I can continue to use it throughout the session. My problem is that the connection really doesn't ever dissappear. I have the problem that once I close the workbook, the project still exists in the VB Editor. How do I get rid of the connection? I am stuck because I declared it as public? I want to keep it open, rather than opening every time I want to use it, because it is faster to keep the connection open.

My code is below.

Option Explicit 'requires variable declaration
'declare global connection
Public cn As ADODB.Connection

Sub OpenDBConnection()
'open db connection
'this happens on workbook open
If cn Is Nothing Then
Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & WCHSBook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"""
.Open
End With
End If
End Sub

View 9 Replies


ADVERTISEMENT

How To Remove Data Connection

Aug 4, 2014

I was messing around with data connections and importing stuff from a network in real time. Cool stuff. But everytime I open ANY excel worksheet on this computer, it tells me "file cannot be found" and refers to one of the first files I used for this. this happens no matter what workbook I am opening.

When I click data --> connections its empty.

View 2 Replies View Related

Excel 2010 :: Remove Data Connection And Keep PivotCache

Nov 26, 2012

With Excel 2010 a yellow warning bar is shown when opening a file with data connection. I don't want to show this warning to other users who will be opening the file, especially when they won't be able to update anything since the original data is on my computer. The logical way would be to remove or disable the connections before sending the file out. But when removing the data connections through Connection window all the pivot tables are converted to static tables, which is not acceptable. Is there any other solution to this? Maybe use a macro?

PS: I know that these warnings can be turned off though Trust Center, but I am not interested in changing these settings for other users.

View 2 Replies View Related

How To Remove Data Connection But Preserve Data

Jul 24, 2013

If I run this vba it removes the external data connection to the pivot table:

ActiveWorkbook.Connections("EXAMPLE").Delete

When I attempt to drill down into the pivot table it states the data connection was removed.

Is there a way to remove the data connection but preserve the data in the pivot cache?

It's probably possible to store the data somewhere else in the document and link the pivot table up to it but that seems cumbersome.

View 4 Replies View Related

Call Public Object From Public Sub?

Aug 14, 2012

I am trying to bring up a form after clicking the "ok" button on another form. Both forms are defined in my public sub, so basically, the module creates both forms, calls the first form, and hides the second form. Then the first form hides itself and shows the second form. However, when second form is defined using "dim", the first form can't find it to show it, and when I make the second form "public" in my public sub, I get the error that it is an invalid attribute or function.

Here is the code from my sub that applies to this error:

Code:
Public Sub PutInEngine()
Dim InputForm As New FrmInputs
InputForm.Show

[Code].....

View 3 Replies View Related

DBGrid Connection Through ADO (SQL)

Jul 18, 2009

to retrieve the data from MS access table in to the DB Grid at user form through MS SQL Query.

I am trying to use ADO for the same.

View 9 Replies View Related

Workbook Connection

Jun 8, 2006

i have two workbooks that use a identical worksheet which is called products (this sheet contains rows of over 19000 products ). The problem is i cannot merge the two workbooks together because they are just too big in size.

Also these workbooks have similar userforms and macros that rely on this product databases (worksheets).

My problem is when i add a new product to of one product databases i have to also add it to the second product database again. Is there a way where i can update both worksheets together without opening both workbooks.

I have three userforms that rely on this worksheet from both workbooks:

frmNewProduct - To add a new product to the worksheet.

frmProductUpdate - To edit, replace or delete products in the worksheet.

frmSearch - To search for products inside the worksheet.

I have also got other define names, worksheets and formulas that rely on these product database worksheets.

View 9 Replies View Related

SAP Connection - Which References

Sep 7, 2006

I'm trying to connect to SAP R/3, and I think I'm not sure which references (Tools --> References) I'm supposed have checked.

All I want to do for now is the following:

Dim sapConn As Object
Set sapConn = CreateObject("SAP. Functions")

Unfortunately, I am getting a "Run-time error '-2147024770 (8007007e)': Automation error. The specified module could not be found."

I have read somewhere random on the internet that I should add "SAP:Remote Function Call: COM Support 1.0 Type Library" which links to the SAPGui Provided library librfc32.dll. However, this alone doesn't seem to work...

View 5 Replies View Related

DB Connection Lockout Other DB Connections

Mar 7, 2007

I have a series of external database connections that I run in Excel, connecting to a Server based DB and running some SELECT statements. (ingres). We may have up to dozen of client machines accessing the ingres DB at any time. All is good at this point but when excel goes to INSERT some calculated data back to the main database, it appears that my Excel spreadsheet connection is locking the database when it connects, keeping other people from using their client connections.

first question: Does anyone know if the connection excel uses to run sql statements via external database connection will indeed prevent other users from connecting to the main database?

second question: if so, is there a setting or something that can make excel more "passive"?

View 9 Replies View Related

VPN Connection Causes Macro Error

Jul 11, 2014

This file connects to a weather API. The laptop I am using connects through a VPN connection. For some reason whenever I am on the VPN if I try to refresh the information I will get an error and the macro will fault out. Other than that the macro works perfectly fine.

Attached is the file in question : Weather Forecast Spreadsheet Draft V12.xlsm‎

When debugging the error goes to:

How can I place in an error management instead of the code just getting blocked out.

View 1 Replies View Related

Write Values From ADO Connection

Jul 12, 2009

i have a ADO Connection. My query is like this:

select [C1] from [values$]
It works, but my problem is to write this values.
Why?
Cause i work with my workbook open (not that from connection) and i have something like 55,000 rows to change value. A complex range:

D2,D11:D12,D14:D20,D32,D42,D52,D62,D72,D82,D92,D101:D102,D104:D112...
I have a loop for each cell in this range, but this process is very slow.

Imagine:

For Each rng In rng
rng.Value = objRecordset(0)
objRecordset.MoveNext
Next rng
55,000? So slow...

I saw something about QueryTable,

View 9 Replies View Related

ActiveSheet.QueryTables.Add Connection:

Jun 13, 2006

Sub WebQuery()
Dim strSearch As String
strSearch = "abc"

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.xyz.com/&=" & strSearch & "", _
Destination:= Range("A1"))
.Name = "search?hl=en&ie=UTF-8&oe=UTF-8&q=" & strSearch & ""
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With

End Sub...

View 6 Replies View Related

Mysql Database Connection

Sep 21, 2006

I'm trying to run som e query using VBA. How can I open a database connection to mySQL?

View 2 Replies View Related

Set Public Variable

Feb 12, 2008

Setting the Public Statement does not work. These are my codes:

Option Explicit
Public Ankis_makro As Boolean
Sub Makro2_Ankis_veckor()
On Error Resume Next
Application. ScreenUpdating = False
Sheets("Listan").Activate
Selection. AutoFilter Field:=1
Selection.AutoFilter Field:=2
Selection.AutoFilter Field:=3
Selection.AutoFilter Field:=4
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=6
Selection.AutoFilter Field:=7
Selection.AutoFilter Field:=8
Selection.AutoFilter Field:=9
Range(Range("J2"), Range("I65536").End(xlUp).Offset(0, 1)).FormulaR1C1 = "=TEXT(RC[-9],""ÅÅÅÅ"")" ...................

What ever I do I can't get the Ankis_makro set to True.

View 2 Replies View Related

Web Data Connection Parameter Problem

Oct 10, 2008

I'm having problems with date parameter for a web connection. I can provide the parameter and type the parameter via message box ... but when I want to reference a cell the query errors out.

View 3 Replies View Related

Assigning Cell Value In Web Query Connection?

Jun 15, 2014

I have a macro which retrieves data from web.It works fine.I just don't know how to assign a cell value in web address.i have attached the code here. i just want to assign activesheet.(range"c2").value for "q?s".

View 1 Replies View Related

VBA Coding To Detect Internet Connection

Nov 4, 2009

Afternoon All - i have an excel workbook that runs on 20 remote machines that i do not have direct access to - i am placing upgrades on the net but looking at finding a way for excel to detect the update what i need it to do first is check if the machine is connected to the internet.

View 6 Replies View Related

ODBC Connection To An Oracle Database

Nov 14, 2009

I am currently querying data from an Oracle database through MS Access and then passing it to Excel for the user to work. Not all users have MS Access so I would like to automate the data pull from Excel

Database information:

The DNS is: a150
The Tables are:

MFE.Items
MFE.Vendors

Sample SQL string would be:

View 2 Replies View Related

Excel 2013 :: VBA Connection To Access?

May 18, 2013

I currently have a workbook that has VBA functions that calculates values by looping through large amounts of data in a few large excel sheets. I want to transfer the data from these sheets into Access and then bring data into the VBA code via an array from the data in Access rather than the array being populated from the data in excel as it currently is. How to create the connection. The access DB will be situated in a public directory on a server. How to create the connection string and then how I call the data from Access? I have just downloaded Office 2013.

View 9 Replies View Related

Stop Internet Connection In VB Works On One PC But Not On

Apr 6, 2007

I have the following code in Excel which stops the connection to the internet

'code below

Option Explicit
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long

Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 0
Private Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 0
Private Declare Function InternetAutodial Lib "wininet.dll" (ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function InternetAutodialHangup Lib "wininet.dll" (ByVal dwReserved As Long) As Long

Sub Stop_BroadBand()

If InternetAutodialHangup(0) Then
End If

End Sub

'code end

View 9 Replies View Related

VBA Set ODBC Connection String For Query

Jul 25, 2008

My workbook has 9 queries, all needing the same string. I would like to have a msgbox pop up, let them enter the directory name, and have that change all the odbc conneciton strings automatically. Can anyone point me in the right direction?

The message box would be a nice touch, but is not necessary, I can change it in the VBA editor if needed.

Currently, they connect using a Visual FoxPro ODBC driver. We setup the connection when we made the queries. Now that they are in on the worksheets, I want to be able to edit them with VBA instead of using the script editor (which is very slow).

View 9 Replies View Related

Access To Excel Data Connection

Nov 9, 2009

I've created a connection which draws information from an access table to excel. The issue is that any numbers (they are ratings from 1-10) that come from access are shown in excel 1 number higher than the correct data that is in access (i.e 10 is shown as 11, 9 as 10, etc). I've looked all over the forum as well as google and can't find any information on how to correct this.

View 9 Replies View Related

How To Dim Array And Its Values As Public

Apr 3, 2014

I am trying to declare a public (or global) array and it's values so I don't have to keep dimensioning it for each function I create.

I was trying things such as:

Public whatever(10) as string

whatever(0) = "something"
whatever(1) = "somethin else"
....

And tried creating an initialize macro in "ThisWorkbook".

View 11 Replies View Related

Macro Can't See Public Variable?

May 26, 2014

I have declared one variable outside of Sub. And in a Sub I gave it a value. Then I run a macro, which should take that value and print it to the cell. However, it is printing a blank cell, not even "0" (I run a macro and anything in that cell is removed).

[Code].....

and then my macro:

[Code]......

How to make so macro see my variable declared outside of this macro?

View 8 Replies View Related

Reseting Public Arrays

Mar 19, 2009

I am using a set of arrays in a module. The arryas are set as public as the module that loads the data is called many times from diffrent other modules that then use the data.

How so I reset the array at the start of the module so each level is "Empty"
so new data can be loaded with no data left over from the last time the array was used.

View 2 Replies View Related

Public Worksheet Declaration

Aug 28, 2009

I'm using a public declaration for a worksheet but I seem to have to initialize it in each routine. Is there a way to set it and leave it? So in a module I have:

View 4 Replies View Related

Making Combobox Value Public

Jun 6, 2014

I have a combo box which is on a worksheet and it's always active/visible. I need to pass on the selection data to another project. I thought I had successfully converted it to a public variable but it doesn't work.

I've indicated that the Tr variable is public and it does populate with the results of the case select but to no avail.
What do I have to do?

Public Tr As String
Public Sub ComboBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

Dim a As String
Select Case ComboBox1.Value
Case "NYF PT"

[Code] .........

View 6 Replies View Related

Public Variables Not Holding The Value

May 14, 2008

I am trying to use a public variable but it is not holding the value when I call another sub.

Here is basically what I have:

Public AcctName as Long

Sub Statments()
There is much more code in here but it is not relevent
AcctName = an account name lets say "frank"

If X XX then
Call Title
End If

End Sub

It then goes to the title sub and executes the code however it is supposed to write out the value held in acctname but it comes up blank instead of as Frank which is the value it held when it left the statments sub. I am new to this public thing and need any help I can get.
Just a note: the spelling is correct and the variable does hold the correct value before title sub is called.

View 9 Replies View Related

Keep Getting Error With Public Variable

Jul 8, 2008

I have a number of userforms that all reference the same worksheet. I wanted to create a public variable for that worksheet so I don't have to keep referencing it in each userform/commandbuttons etc. So I inserted a module and placed this declaration.

Option Explicit
Public MySh As Worksheet
Set MySh = ActiveWorkbook.Sheets("sheetName")
And I referenced it in a UserForm commandbutton

Private Sub CommandButton2_Click()
MySh.Range("i4") = Me.ComboBox1
MySh.Range("i5") = Me.TextBox1
End Sub

View 9 Replies View Related

Public Variables Duration

Jul 21, 2009

I've recently been experiencing some strange phenomena in relation to public variables. It seems that if I run separate routines in quick enough succession (e.g. press a button twice within a couple of seconds), the memory of the public variable "hangs over" into the second routine.

The routines, however, are completely separate events. And I'm not using userforms or anything like that in order to keep VBA running in the background. In which case it seems that Public variables don't always get set to nothing with the end of the final sub in a routine. Has anyone else experienced anything like this? I was under the impression only Static variables could do this.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved