Function for query in VBA

Knight of Nee

Board Regular
Joined
Aug 4, 2003
Messages
124
hi the following module should perform a query hardcoded into my VBA project but for some reason it dosnt can somebody tell me whats wrong with it. it get a

Code:
Function JQuery(query As String) As String

On Error GoTo Fail

Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim returnVal As String

Set db = CurrentDb
Set rs = db.OpenRecordset(query)

'clean up

returnVal = "" & rs(0)
  
    
rs.Close

Set rs = Nothing
Set db = Nothing



JQuery = returnVal

Exit Function


Fail:

MsgBox ("FAIL!")

End Function

i get a compile error user defined type not defined on the "Dim rs As DAO.Recordset" line. I am using access 2000 on xp

Thanks
Craig
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Craig, did you set a reference to the DAO object library in your project? sounds like you need to so VB will recognize the variable type
 
Upvote 0
In the VB Editor, go to Tools: References. Make sure that you have a checkbox next to the most recent DAO object library.
 
Upvote 0
Hi Craig,

yoiu will have a DAO library ref, but it's Microsoft DAO ... You'll probably have several, just select the latest one.

Denis
 
Upvote 0

Forum statistics

Threads
1,221,844
Messages
6,162,346
Members
451,760
Latest member
samue Thon Ajaladin

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