Code Acting Up

George Too

Registered User.
Local time
Yesterday, 19:07
Joined
Aug 12, 2002
Messages
198
Hello All,
Can anyone tell me why the following code is closing the database? This code sits behind the After Update event of a combo box:

Private Sub cmbDefect_AfterUpdate()
On Error GoTo RptErr

'Search for claims in the Film_Claims DB
If Me.cmbDefect = "Curl Issues" Or Me.cmbDefect = "Wrinkles" Then
DoCmd.OpenForm "frmFilmComplaintInvestigation"
Cancel = True
End If

RptErr:
If Err = 2501 Then
Resume Next
End If
End Sub

The form that opens up (frmFilmComplaintInvestigation) has the following code on its On Open event:

Private Sub Form_Open(Cancel As Integer)

If Me.RecordsetClone.EOF Then
MsgBox "No film complaints were found based on the criteria you entered."
Cancel = True
End If

End Sub


When executed, if no records are found I should get the message (which I do), but when I press on 'OK' the database closes up.

What's going on?

Thanks,
George
 
If Me.cmbDefect = "Curl Issues" Or Me.cmbDefect = "Wrinkles" Then
DoCmd.OpenForm "frmFilmComplaintInvestigation"
Cancel = True
End If


why do you have Cancel=True here? it doesn't look as if you need it
 
Not sure about why your code is closing Access but this is what I use to test if the record source is null and if true then I close the form. Try it...
Code:
Private Sub Form_Open(Cancel As Integer)
     
    If Me.RecordsetClone.RecordCount = 0 Then
        MsgBox "There are zero records in the data source!", vbInformation, "No Records Found"
        DoCmd.Close acForm, Me.Name
    End If
     
End Sub
 

Users who are viewing this thread

Back
Top Bottom