Complicated Form-Query-Form Problem

G

Guest

I've created a form (frmComboSearch) with combo boxes for various fields from
a table (tblMasterPartsList). After selecting the values from the combo
boxes, a query (qryComboSearch) is run using the data from the combo boxes.
This is all activated by a command button. What I'm trying to do is have a
new form open after the command button is pushed, instead of opening the
query. I've created a form (frmqryComboSearch) to display the query results,
and everything is working fine. The one problem i've run into is that I want
a dialogue box to pop up if there are no record matches for the query,
stating such, and giving the user a command button to return to the original
form with the combo boxes. So far, i've tried:

1. the On_Open Event in the second form (frmqryComboSearch):

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Sorry, there are no Parts that match your search criteria."
Cancel = True
End If

the dialogue pops up fine, but when it tries to go back to the original
form, i get the error message "Run-time error'2501': The OpenForm action was
canceled."


2. the On_Click Event of the command button in the first form
(frmComboSearch):


Private Sub cmdSearch_Click()
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "Sorry, there are no Parts that match your search criteria."
Cancel = True
End If

DoCmd.OpenForm "frmqryComboSearch", acNormal
DoCmd.Close acForm, "frmComboSearch"
End Sub

Which returns the error message "Run-time error '7951': You entered an
expression that has an invalid reference to the RecordsetClone property."


I'm not sure what else to try... any help would be greatly appreciated!
 
G

Guest

Change this line
If Me.RecordsetClone.RecordCount = 0 Then
To
If Me.Recordset.RecordCount = 0 Then

I don't know for sure if this is true for forms, but I know it is required
for reports. If you cancel the Open event, even using the Cancel, the
calling form will raise an error and you have to trap for it. So try
trapping for it in the error handler for cmdSearch_Click().
 

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