Erin Cimbrie
Registered User.
- Local time
- Today, 07:12
- Joined
- May 10, 2007
- Messages
- 12
The goal here is to open a query where a field = a control on a form [Forms]![Billable Query Form]![ProjectNumberOnBillable]"). The criteria is in the query. I want to run the query and check it for records. The debugger stops the code at Set qd.Parameters.
Private Sub CmdInvoice_Click()
On Error GoTo cmdInvoice_Err
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qd As DAO.QueryDef
Set db = CurrentDb
Set qd = db.QueryDefs![InvoiceSearchForInvoice]
Set qd.Parameters("[Forms]![Billable Query Form]![ProjectNumberOnBillable]") = [Forms]![Billable Query Form]![ProjectNumberOnBillable]
Set rs = qd.OpenRecordset
If [Forms]![Billable Query Form]![ProjectNumberOnBillable] Is Null Then
Beep
MsgBox "You must enter a project number on the Billable Query form", vbInformation, "No Project Number"
Else
If rs.EOF Then
' open the invoice form in Add Mode
DoCmd.OpenForm "Invoice", acNormal, "", "", acAdd, acNormal
' enter the project number that was typed on the Billable Form
Forms!Invoice!Number = Forms![Billable Query Form]!ProjectNumberOnBillable
' enter Today's date in invoice date
Forms!Invoice![Invoice Date] = Date
DoCmd.RunCommand acCmdSaveRecord
Else
DoCmd.OpenForm "Invoice", acNormal, "", "[Number]=[Forms]![Billable Query Form]![ProjectNumberOnBillable]", , acNormal
End If
qd.Close
End If
cmdInvoice_Exit:
Exit Sub
cmdInvoice_Err:
MsgBox Error$
Resume cmdInvoice_Exit
End Sub
Private Sub CmdInvoice_Click()
On Error GoTo cmdInvoice_Err
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim qd As DAO.QueryDef
Set db = CurrentDb
Set qd = db.QueryDefs![InvoiceSearchForInvoice]
Set qd.Parameters("[Forms]![Billable Query Form]![ProjectNumberOnBillable]") = [Forms]![Billable Query Form]![ProjectNumberOnBillable]
Set rs = qd.OpenRecordset
If [Forms]![Billable Query Form]![ProjectNumberOnBillable] Is Null Then
Beep
MsgBox "You must enter a project number on the Billable Query form", vbInformation, "No Project Number"
Else
If rs.EOF Then
' open the invoice form in Add Mode
DoCmd.OpenForm "Invoice", acNormal, "", "", acAdd, acNormal
' enter the project number that was typed on the Billable Form
Forms!Invoice!Number = Forms![Billable Query Form]!ProjectNumberOnBillable
' enter Today's date in invoice date
Forms!Invoice![Invoice Date] = Date
DoCmd.RunCommand acCmdSaveRecord
Else
DoCmd.OpenForm "Invoice", acNormal, "", "[Number]=[Forms]![Billable Query Form]![ProjectNumberOnBillable]", , acNormal
End If
qd.Close
End If
cmdInvoice_Exit:
Exit Sub
cmdInvoice_Err:
MsgBox Error$
Resume cmdInvoice_Exit
End Sub