Error 94

Robster

Registered User.
Local time
Yesterday, 22:08
Joined
Mar 13, 2014
Messages
60
I have a button that opens a form which is based on a query.
The query has a prompt so when you click the button the prompt pops up.
However if nothing is entered you get a VB error 94 error.

How do i get it to show a msgbox if the search is empty?
 
Hi Robster

2 options for you:
1) You can use the Report's OnNoData event for this. For example, the following code

Code:
Private Sub Report_NoData(Cancel As Integer)
    MsgBox "No data found! Closing report."
    Cancel = True
End Sub
This will automatically close the report if there are no records in the underlying source.

However, if you're opening the report from code behind a form, you need to handle the error that's generated as a result.

Code:
Private Sub TestNoData_Click()
    On Error Resume Next
    DoCmd.OpenReport "SomeReport", acViewPreview
    If Err = 2501 Then Err.Clear
End Sub

2) in the command buttons onclick event, before you open the report, do a DCOUNT("*",querynamereportisbasedon). If this is 0, produce your message box and avoid opening the form
 
I think the error is actually coming from the onCurrent code which displays a picture on the page.
The code is :
EmployeePic.Picture = Photo

Where Photo is a field with a path to the object.
I tried changing it to the below but got and error msg saying object required.

If Form_AdminActiveStaff.Photo Is Null Then
MsgBox "you havent selected an employee"
Else: EmployeePic.Picture = Photo
 
..
If Form_AdminActiveStaff.Photo Is Null Then
MsgBox "you havent selected an employee"
Else: EmployeePic.Picture = Photo
Try the below code instead.
Code:
If [COLOR=Red]IsNull(Me.[/COLOR]Photo[COLOR=Red])[/COLOR] Then
  MsgBox "you havent selected an employee"
    Else
  EmployeePic.Picture = Photo
Endif
 

Users who are viewing this thread

Back
Top Bottom