If no record is found....

PS65

Registered User.
Local time
Today, 12:03
Joined
Oct 11, 2005
Messages
13
Hi,

Basically, I have a query which brings up a customers details when they enter the Name and DOB.

However, lets say they get it wrong, or don’t even type anything in…….the form just opens with a blank section.

Is there any way to make it give an alert say “No Record Found”.

Thanks
 
If you had searched the forum then you would have found a few variations of this code which will close the form if the record source contains no records. Put it in the forms OnOpen event.
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
 
ghudson said:
If you had searched the forum then you would have found a few variations of this code which will close the form if the record source contains no records. Put it in the forms OnOpen event.
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

Hi, there seems to be a problem...it says "Run Time Error 7951".

When I debug, it says there is a problem with the following:

Code:
    If Me.RecordsetClone.RecordCount = 0 Then

Any ideas?
 
This code does not work for reports as the Me.recordsetclone.recordcount =0 is not allowed. Is there a similar way for not opening reports with no data? Thanks
 
ted.martin said:
This code does not work for reports as the Me.recordsetclone.recordcount =0 is not allowed. Is there a similar way for not opening reports with no data? Thanks

Try something like this in the 'On No Data' event of your report:

MsgBox "Sorry this report has no records to display"
Cancel = True
 
jrjr said:
Try something like this in the 'On No Data' event of your report:

MsgBox "Sorry this report has no records to display"
Cancel = True

Hey, Thanks man, it works.

:D
 

Users who are viewing this thread

Back
Top Bottom