Modify Code to add message box

I am having problems modifying this code  so that it will only give a message box saying "no record found matching criteria " and not open form when there is no record found.

Function LOCATIONREPORT()
On Error GoTo LOCATIONREPORT_Err

    DoCmd.OpenForm "CALLHISTORY1", acNormal, "", "[casenumber]=[Enter Case Number]", , acNormal


LOCATIONREPORT_Exit:
    Exit Function

LOCATIONREPORT_Err:
    MsgBox Error$
    Resume LOCATIONREPORT_Exit

End Function

Open in new window

mickeyshelley1Asked:
Who is Participating?
 
mbizupCommented:
Modify that code as follows:

Function LOCATIONREPORT()
On Error GoTo LOCATIONREPORT_Err

    DoCmd.OpenForm "CALLHISTORY1", acNormal, "", "[casenumber]=[Enter Case Number]", , acNormal


LOCATIONREPORT_Exit:
    Exit Function

LOCATIONREPORT_Err:
    if err.number = 2501 then Exit Function
    MsgBox Error$
    Resume LOCATIONREPORT_Exit

End Function

Open in new window



And place this in the Open Event of the form you are opening:

Private Sub Form_Open(cancel as integer)
        If Me.RecordsetClone.Recordcount = 0 then
                 msgbox "No records found"
                  cancel = true
         end if
End sub

Open in new window

0
 
mickeyshelley1Author Commented:
Thank you very much it works great!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.