I have a single query(Query1) that I use with two different forms (Form1 + Form2).
When a button on either form is pressed, another form (Form3) opens, and the recordsource is set to Query1.
The query's criteria makes reference to Form1 so in the code called by pressing the button in Form2, I use a querydef and set the parameters for the criteria by code.
This is all fine except now, instead of setting Form3's recordsource to Query1's name, I need to set it to the querydef.
For some reason I can't do this, does anyone know how?Here's a little sample of the code I've tried:
Dim db As DAO.Database, rs As DAO.Recordset, qdf As DAO.QueryDef
Dim stDocName As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qryEmployeesRelatedToCourse"
qdf![Forms!frmCourseVariables!CCode] = Forms![frmCourses]![CCode]
qdf![Forms!frmCourseVariables!CoDate] = "*"
Set rs = qdf.OpenRecordset()
stDocName = "qryEmployeesRelatedToCourse"
DoCmd.OpenForm "frmEmployees"
'This is the all important line
Form_frmEmployees.RecordSource = qdf
Form_frmEmployees.Requery
Cheers,
Pete
When a button on either form is pressed, another form (Form3) opens, and the recordsource is set to Query1.
The query's criteria makes reference to Form1 so in the code called by pressing the button in Form2, I use a querydef and set the parameters for the criteria by code.
This is all fine except now, instead of setting Form3's recordsource to Query1's name, I need to set it to the querydef.
For some reason I can't do this, does anyone know how?Here's a little sample of the code I've tried:
Dim db As DAO.Database, rs As DAO.Recordset, qdf As DAO.QueryDef
Dim stDocName As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qryEmployeesRelatedToCourse"
qdf![Forms!frmCourseVariables!CCode] = Forms![frmCourses]![CCode]
qdf![Forms!frmCourseVariables!CoDate] = "*"
Set rs = qdf.OpenRecordset()
stDocName = "qryEmployeesRelatedToCourse"
DoCmd.OpenForm "frmEmployees"
'This is the all important line
Form_frmEmployees.RecordSource = qdf
Form_frmEmployees.Requery
Cheers,
Pete