Compile error user defined type not defined

C

ChuckW

Hi,

I created a form about a year ago that allows people to select items from a
list and then generates a report on those items. It worked fine for many
months but now I am getting an error that says Compile Error - User defined
type not defined. It takes me to the VBA editor and has Dim qdf as
DAO.QueryDef highlighed. Can anyone help me with resolving this?

Thanks,
 
O

Ofer

Check the reference to see if you are missing anything, aspecialy Microsoft
DAO.

While in code, select tools > reference
 
C

ChuckW

Ofer,

Thanks for your help. I am not sure what references should be checked. the
four that are checked are Visual basic for applications, Microsoft Access
10.0 Object Libary, OLE Automation, and Microsoft Active X Data Objects 2.1
Library. The application will all you to select certain items from a list
box and then click on a command button to confirm and then another command
button to run a report. The report pulls data from a table and gives
detailed information on the products selected from the list box. Here is a
list of the VBA code that runs this form. Any thoughts on which reference
needs to be checked?

Option Compare Database
Option Explicit

Private Sub cmdReport_Click()
Dim qdf As DAO.QueryDef
Dim db As DAO.Database
Dim varItem As Variant
Dim StrWhere As String
'You could delete and recreate the query each time,
'I generally leave the query and just modify the SQL
'On Error Resume Next
'db.QueryDefs.Delete ("tmpSelectProducts")
'On Error GoTo Proc_err
Set db = CurrentDb()
Set qdf = db.QueryDefs("tmpSelectProducts")
For Each varItem In Me.List0.ItemsSelected
StrWhere = StrWhere & "ProductName=""" & _
Me.List0.ItemData(varItem) & """ OR "
Next varItem
'Add "Where" and Trim off Trailing " Or "
If Len(StrWhere) > 0 Then
StrWhere = "Where " & Left(StrWhere, Len(StrWhere) - 4)
End If
qdf.SQL = "Select ProductName from Products " & StrWhere
DoCmd.OpenReport "rptSelectedProducts", acViewPreview

End Sub
 
O

Ofer

As I wrote in the first post, you need Microsoft DAO, look for it in the list
and check it.
 

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