A question about DAO

termeric

Active Member
Joined
Jun 21, 2005
Messages
280
Good Morning,

I've used the same piece of code for quite some time whihc uses DAO to pull a query form access into excel. this has always been used with the MDB formatted database in the past. Recently, i created a new database, using the newer ACCDB format. When i went to use my code to pull a query over, i received this message.

Run-time error '3343':
Unrecognizes database format 'C:\data\RenewalDB.accdb'


my code is below, the only change i made form it work with MDB to not workign with ACCDB was to change to database path and the Query name. I also took the pasword out from this line Set db = DAO.DBEngine.Workspaces(0).OpenDatabase("C:\Data\SSTracking.mdb", False, False, ";PWD=xxxx")

any ideas?


Code:
Private Sub FirstStep()
'GetQueryDAO
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer, iNumCols As Integer
Dim wb As Workbook, ws As Worksheet, ws2 As Worksheet
 
 
'--------------------------------------------------------------------
'Requires a reference to the DAO Object Library
'   1) in the visual basic editor, go to Tools | References
'   2) check the box for Microsoft DAO 3.6 Object Library (or higher)
'--------------------------------------------------------------------
    
    
'** Suspend automatic Calculations
    Application.Calculation = xlCalculationManual
    
'** Connect to the Database
    Set db = DAO.DBEngine.Workspaces(0).OpenDatabase("C:\Data\Renewaldb.accdb", False, False)
    Set rs = db.OpenRecordset("Assignments All Lines", dbOpenSnapshot)
    
  
'** Unhide, Select Paste and clear the old data
    Set ws = Sheets("Sheet1")
    With ws
        .Visible = True
        .Select
        .Cells.ClearContents
    End With
    
 
    
'** Write Column Headers
    iNumCols = rs.Fields.Count
    For i = 1 To iNumCols
        ws.Cells(1, i).Value = rs.Fields(i - 1).Name
    Next
 
'** Write the data
    ws.Range("A2").CopyFromRecordset rs
    'wb.Activate
    'ws.Activate
    
'** Close the connections
    rs.Close
    db.Close
 
'** Updates the Translate Formulas  and Reactivate calculations
    Application.Calculation = xlCalculationAutomatic



Thanks,

Christian
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Change your references - uncheck the DAO 3.6 library and use the Microsoft Office Access Database Engine instead.
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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