MS Access to Excel

tsgdes

New Member
Joined
Aug 8, 2006
Messages
31
Hi,
I'm trying to use DAO in execl to pull some records from a database. I can do this no probs using ADO but when I use DAO (3.6) I get a data mis-match error. The code I'm using is below and the problem occurs at the populate recordset line.

Anybody help?

Thanx

Sub dbquery()

Dim myDatabase As Database
Dim strSQL As String
Dim rstFromQuery As Recordset

'open database
myDatabase = OpenDatabase("C:mydatabase.mdb")

' build query
strSQL = "SELECT * from myTable"

'populate recordset
Set rstFromQuery = myDatabase.OpenRecordset(strSQL, dbOpenSnapshot)

'display records
MsgBox "there are " & rstFromQuery.RecordCount & _
" records that were returned"


rstFromQuery.MoveLast


MsgBox "there are " & rstFromQuery.RecordCount & _
" records that were returned"

rstFromQuery.Close
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Perhaps you need to declare the Recordset/Database as DAO objects?
Code:
Dim myDatabase As DAO.Database
Dim rstFromQuery As DAO.Recordset
By the way if you can do it with ADO why do you want to do it with DAO?
 
Upvote 0
has worked now I needed to put the priorty in the references of DAO above ADO. I'm using DAO becuase it easier to move through the recordset

Cheers Des
 
Upvote 0
Des

Glad you've got it sorted.:)

But I'm still wondering why DAO instead of ADO, as far as I'm aware don't they have basically the same methods for moving through recordsets?
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,517
Members
448,968
Latest member
Ajax40

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