Steve:
The form must be open and with a value in the control before opening the
query. You can’t just open a query from the database window and get it to
open the form automatically. With a report based on a query you can get it
to do this, however, by putting the following code in the report’s Open event
procedure:
Const FORMNOTOPEN = 2450
Dim frm As Form
On Error Resume Next
Set frm = Forms! frmCustomerCombo
If Err = FORMNOTOPEN Then
DoCmd.OpenForm "frmCustomerCombo"
Cancel = True
Else
If Err <> 0 Then
' unknown error
MsgBox Err.Description, vbExclamation, "Error"
End If
End If
You’d then need code in the click event of a button on the form to open the
report:
DoCmd.OpenReport, "YourReportName", acViewPreview
To open a form based on the query in the same way you need to delete the
query name from the form’s RecordSource property in its properties sheet and
amend the code for the form’s Open event slightly:
Const FORMNOTOPEN = 2450
Dim frm As Form
On Error Resume Next
Set frm = Forms! frmCustomerCombo
If Err = FORMNOTOPEN Then
DoCmd.OpenForm "frmCustomerCombo"
Cancel = True
Else
If Err <> 0 Then
' unknown error
MsgBox Err.Description, vbExclamation, "Error"
Else
Me.RecordSource = "YourQueryName"
End If
End If
The frmCustomerCombo form would now need a button to open the form bound to
the query with:
DoCmd.OpenForm "YourFormName"
Ken Sheridan
Stafford, England