I am working on unknown ground, here, so there is much that I do not know. I want to invoke a query from a command button on a form and Wayne Ryan suggested I learn more about queryDefs and use that approach. After a little study, it seems to be the way to go. When I searched the Query Forum, I found some example code from Jon K and modified it to fit my needs. The code is:
Dim db As DAO.Database
Dim qDef As DAO.QueryDef
Dim RsDischarges As DAO.Recordset
Set db = CurrentDb()
Set qDef = db.QueryDefs("qry Discharges")
qDef.Parameters("PN_PlntID") = Forms!FrmFunctions!txtPN_PlntID
qDef.Parameters("SNF_ASSM") = Forms!FrmFunctions!txtSNF_ASSMID
Set RsDischarges = qDef.OpenRecordset
When I try to run the code I get a "Compile error: User-Defined type not defined" message. So now I am confused. Isn't that what the dimension statements at the beginning do for me? Can anyone provide some insight into what I am doing wrong? Thanks.
Dim db As DAO.Database
Dim qDef As DAO.QueryDef
Dim RsDischarges As DAO.Recordset
Set db = CurrentDb()
Set qDef = db.QueryDefs("qry Discharges")
qDef.Parameters("PN_PlntID") = Forms!FrmFunctions!txtPN_PlntID
qDef.Parameters("SNF_ASSM") = Forms!FrmFunctions!txtSNF_ASSMID
Set RsDischarges = qDef.OpenRecordset
When I try to run the code I get a "Compile error: User-Defined type not defined" message. So now I am confused. Isn't that what the dimension statements at the beginning do for me? Can anyone provide some insight into what I am doing wrong? Thanks.