Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

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

0
mickeyshelley1
Asked:
mickeyshelley1
1 Solution
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now