QueryDef is a user-defined type?

W

wentex

I want to change the SQL for a query based on input parameters in a macro.
Can anyone tell me why VBA gives me the Compile Error "User-defined type not
defined" for variable qdf? Everything I've read indicates that QueryDef
should be a valid type, but my system doesn't seem to know it. Should I be
using AccessObject (or something like it) instead? Here's my code:

Sub sCreateSQL()

Dim qdf As QueryDef
Dim strSQL, strFromDate, strToDate, tmpQuery As String

tmpQuery = "QryTemp"
strFromDate = gblYrMo & "00"
strToDate = gblYrMo & "99"
strSQL = "SELECT * FROM tblOne WHERE ((tblOne.Dt>""" & strFromDate &
""") and (tblOne.Dt<""" & strToDate & """));"

qdf = CurrentDb.CreateQueryDef(tmpQuery, strSQL)
qdf.SQL = strSQL

End Sub 'sCreateSQL

Thanks!
 
S

Stuart McCall

wentex said:
I want to change the SQL for a query based on input parameters in a macro.
Can anyone tell me why VBA gives me the Compile Error "User-defined type
not
defined" for variable qdf? Everything I've read indicates that QueryDef
should be a valid type, but my system doesn't seem to know it. Should I
be
using AccessObject (or something like it) instead? Here's my code:

Sub sCreateSQL()

Dim qdf As QueryDef
Dim strSQL, strFromDate, strToDate, tmpQuery As String

tmpQuery = "QryTemp"
strFromDate = gblYrMo & "00"
strToDate = gblYrMo & "99"
strSQL = "SELECT * FROM tblOne WHERE ((tblOne.Dt>""" & strFromDate &
""") and (tblOne.Dt<""" & strToDate & """));"

qdf = CurrentDb.CreateQueryDef(tmpQuery, strSQL)
qdf.SQL = strSQL

End Sub 'sCreateSQL

Thanks!

Check your references for an entry "DAO 3.x" where x is the highest value on
your system.

Also it helps if you disambiguate:

Dim qdf As DAO.QueryDef
 
J

John Spencer

What version of Access?
Do you have the DAO library selected as one of the references? You need
to add it to the list of references.

Then
Dim qdf as QueryDef
should no longer generate an error.

These types are defined in the DAO object library. By default, the DAO
object library is not referenced in an Access 2000 database (ADO is
instead). To solve the problem:

1. In the Microsoft Visual Basic window, choose References from the
Tools menu.

2. In the list of available references, check "Microsoft DAO 3.6 Object
Library".

3. Use the Priority buttons to move the entry for "Microsoft DAO 3.6
Object Library" above the entry for "Microsoft ActiveX Data Objects 2.1
Library".
This is to resolve conflicts between types in DAO and ADO (like Field)
that have the same name. You can also avoid these conflicts by
qualifying your variable declarations, as in:
Dim fld As DAO.Field
instead of
Dim fld As Field

4. Click OK.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top