blanchard306
03-24-2016, 10:53 AM
I have VBA that I use for importing Access queries into an Excel file but I am having trouble with making it prompt the user for the table name. Below is my code. Thanks
Application.DisplayAlerts = False
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=\\Prdhilfs03\l&i-sales&mkt\WORKAREA\Agencyservices\Accou" _
, _
"nting\AGY\Databases\DatabaseAudit.mdb;Mode=Share Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:" _
, _
"Registry Path="""";Jet OLEDB: Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB: Database Locking Mode=0;Jet OLEDB:Global Parti" _
, _
"al Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet" _
, _
" OLEDB:Encrypt Database=False;Jet OLEDB: Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OL" _
, _
"EDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False" _
), Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdTable
.CommandText = Array("NEED PROMPT HERE")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = _
"\\Prdhilfs03\l&i-sales&mkt\WORKAREA\services\Accounting\AGY\Databases\DatabaseAudit.mdb"
.ListObject.DisplayName = "Table_DatabaseAudit"
.Refresh BackgroundQuery:=False
End With
Application.DisplayAlerts = True
Application.DisplayAlerts = False
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=\\Prdhilfs03\l&i-sales&mkt\WORKAREA\Agencyservices\Accou" _
, _
"nting\AGY\Databases\DatabaseAudit.mdb;Mode=Share Deny Write;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:" _
, _
"Registry Path="""";Jet OLEDB: Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB: Database Locking Mode=0;Jet OLEDB:Global Parti" _
, _
"al Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet" _
, _
" OLEDB:Encrypt Database=False;Jet OLEDB: Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OL" _
, _
"EDB:SFP=False;Jet OLEDB:Support Complex Data=False;Jet OLEDB:Bypass UserInfo Validation=False" _
), Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdTable
.CommandText = Array("NEED PROMPT HERE")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = _
"\\Prdhilfs03\l&i-sales&mkt\WORKAREA\services\Accounting\AGY\Databases\DatabaseAudit.mdb"
.ListObject.DisplayName = "Table_DatabaseAudit"
.Refresh BackgroundQuery:=False
End With
Application.DisplayAlerts = True