Trouble Querying Access From Excel - VBA

bubbapost

Board Regular
Joined
Mar 11, 2009
Messages
116
Hello,

I keep getting the error "Unrecognized database format" when running this code and I can't figure out why.

Any ideas?

Any ideas on how to fix it?

Code:
Sub ImportAgentTablesDAO()
Dim AgentConn As DAO.Database
Dim AgentRec As DAO.Recordset
Dim AgentQry As DAO.QueryDef
Dim DataSource As String
Dim Provider As String
Dim AgentTbl As String
Dim i As Long
 
DataSource = "G:\U\WCCCTU\TOOLS\Time Off Tracker Backup\Agent Tables.accdb"
AgentTbl = "Agent Info"
 
Set AgentConn = DBEngine.OpenDatabase(DataSource)
Set AgentQry = AgentConn.QueryDefs("QryAgents")
Set AgentRec = AgentQry.OpenRecordset
 
ActiveSheet.Range("A1").CopyFromRecordset AgentRec
 
For i = 1 To AgentRec.Fields.Count
    ActiveSheet.Cells(1, i).Value = AgentRec.Fields(i - 1).Name
Next i
 
End Sub

Thank you!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Are you using Excel 2007+?

Do you get a run-time error -2147467259 or 3343?
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,936
Members
449,094
Latest member
teemeren

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