Sandra Smith
asked on
Query ACCESS 2003 database table
I have a simple need to query the database and have the enter contents of a table, tblHolidays, end up on an Excel worksheet. It is a small table and I have the below, but it does not link the Commandtype. Can I pass the table name as an array?
sandra
Sub GetHolidays()
Dim cnn As New ADODB.Connection
Dim strPath As String
ThisWorkbook.Worksheets("H olidays"). Activate
Range("A1").Activate
strPath = "\\Sf1\user1\shared\Deposi tServices\ CIA\SOS_AP PLICATIONS \ADMIN\PRD \Admin.mdb "
With cnn
.Open "Provider=Microsoft.Jet.OL EDB.4.0; Data Source=" & strPath & ";" 'Create DB connection
.CommandType = xlCmdTable
.CommandText = Array("tblHolidays")
.SourceDataFile = strPath
.ListObject.DisplayName = "Holidays"
.Refresh BackgroundQuery:=False
End With
End Sub
sandra
Sub GetHolidays()
Dim cnn As New ADODB.Connection
Dim strPath As String
ThisWorkbook.Worksheets("H
Range("A1").Activate
strPath = "\\Sf1\user1\shared\Deposi
With cnn
.Open "Provider=Microsoft.Jet.OL
.CommandType = xlCmdTable
.CommandText = Array("tblHolidays")
.SourceDataFile = strPath
.ListObject.DisplayName = "Holidays"
.Refresh BackgroundQuery:=False
End With
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I do not want to export from Access to Excel, but bring in each month the holiday table into a particular worksheet in a workbook with other tabs that use this data. Thus, simply doing a transfer would not work. but the importAccess did the trick.
Thank you both.
Thank you both.
Dim strTableName As String
strTableName = "tblHolidays"
DoCmd.TransferSpreadsheet acExport, , strTableName, "C:\YourFolder\" & strTableName & ".xls", True