Importing data in Excel 2007 using Access query

sp1234

New Member
Joined
Sep 25, 2009
Messages
5
Hi, I'm running an Excel 2007 macro that imports data from an Access 2007 database by calling an Access query. When the database file is on my computer, everything works perfectly. However, when the file is in a network folder and I run the same macro (after changing the filepath, of course), I get a message asking me: "Do you want to connect to 'O:\EXP\Data\Test\Cycle.mdb'?". If I click "yes", the macro transfers the data correctly. The macro then has to call another query and I'm getting the same message. The process is repeated for 15 queries in two different databases, so getting this message everytime is very annoying. Would anybody know how to fix this? If it cannot be fixed, is it possible to write code to answer yes automatically to this message? Here is an example that is used in my macro to call the query and import the data:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
>>><o:p> </o:p>
' Import Access database:<o:p></o:p>
<o:p></o:p>
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _<o:p></o:p>
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=O:\EXP\Data\Test" _<o:p></o:p>
, _<o:p></o:p>
"\Cycle.mdb;Mode=ReadWrite;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Databas" _<o:p></o:p>
, _<o:p></o:p>
"e Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bul" _<o:p></o:p>
, _<o:p></o:p>
"k Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet " _<o:p></o:p>
, _<o:p></o:p>
"OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Co" _<o:p></o:p>
, "mplex Data=False"), Destination:=Range("$AA$4")).QueryTable<o:p></o:p>
.CommandType = xlCmdTable<o:p></o:p>
.CommandText = Array("qrtTransfer")<o:p></o:p>
.RowNumbers = False<o:p></o:p>
.FillAdjacentFormulas = False<o:p></o:p>
.PreserveFormatting = True<o:p></o:p>
.RefreshOnFileOpen = False<o:p></o:p>
.BackgroundQuery = True<o:p></o:p>
.RefreshStyle = xlInsertDeleteCells<o:p></o:p>
.SavePassword = False<o:p></o:p>
.SaveData = True<o:p></o:p>
.AdjustColumnWidth = True<o:p></o:p>
.RefreshPeriod = 0<o:p></o:p>
.PreserveColumnInfo = True<o:p></o:p>
.SourceDataFile = _<o:p></o:p>
"O:\EXP\Data\Test\Cycle.mdb"<o:p></o:p>
.ListObject.DisplayName = "Table_Cycle8"<o:p></o:p>
.Refresh BackgroundQuery:=False<o:p></o:p>
End With<o:p></o:p>
<o:p></o:p>
>>><o:p> </o:p>
<o:p> </o:p>
Any help would be greatly appreciated. Thanks.

Sebastian <o:p></o:p>
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi sp

Try adding your networked DB to the Access trusted locations.

In 'Access Options'....'Trust Centre'....'Trust Centre settings'
 
Upvote 0
I added the database folder to my trusted locations and also checked the "Allow trusted locations on my network (not recommended)". However, I'm still getting the same message. Any other idea?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
Sebastian<o:p></o:p>
 
Upvote 0
Sebastion

Yes .... tried and tested this time (sorry for misleading you earlier)

At the start of your macro place

Application.displayalerts = False

and then at the end

Application.displayalerts = True
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

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