close connection and query from excel vba

vineet78

Board Regular
Joined
Oct 22, 2017
Messages
73
I am trying to close connection but getting error that data is being refreshed in background
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Are you working with a very large data set? If not, you can turn background refresh off from the beginning.
 
Upvote 0
If I set up background query refresh as false then how will i get the data based on query please.
Following is the code i am using to extract data

With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=dbname" _
, _
"Jet OLEDB:Bypass UserInfo Validation=False" _
), Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdTable
.CommandText = Array("SELECT * From [BPC_1] WHERE Region like '" & Reg & "' AND [Zone] like '" & zn & "' AND [Country] like '" & cty & "'AND [Fn L1] like '" & fn1 & "'AND [Fn L2] like '" & fn2 & "'AND [Fn L3] like '" & fn3 & "'AND [Geography] like '" & geo & "' AND [Cate L4] like '" & cat & "'")
.PreserveFormatting = True
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.SourceDataFile = _
"\\pnccfsdg01\Dubai_AC_Finance\Dubai AC Controllership\GL Close Accountants\vg\GOE-APAC.accdb"
.ListObject.DisplayName = "Table_ExternalData_14"
.Refresh BackgroundQuery:=True
End With
 
Upvote 0
Thanks Worf !! :)_
I could solve it now by putting backgroun refresh as false , earlier was missing it

Cheers

Thanks a tonne !!
 
Upvote 0

Forum statistics

Threads
1,216,756
Messages
6,132,535
Members
449,733
Latest member
Nameless_

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top