Solved msg box if no Data (1 Viewer)

theinviter

Registered User.
Local time
Today, 01:33
Joined
Aug 14, 2014
Messages
240
Dear guys
need help

I Have a list in a form, once you click on any items it will go to record in the form, but if there is no record it go to first record, so i need that if no record then show a message " No Record Found"
i tried this code .

Private Sub List6_DblClick(Cancel As Integer)
On Error GoTo errhandler:
n = 1 / 0 ' cause an error
'Move to the record selected in the control

Me.MRN_Query.Form.RecordsetClone.FindFirst "[Item] = '" & Me.List6.Value & "'"

Me.MRN_Query.Form.Bookmark = Me.MRN_Query.Form.RecordsetClone.Bookmark

Exit Sub
errhandler:
' error handling code
Resume Next




End Sub
 

June7

AWF VIP
Local time
Today, 00:33
Joined
Mar 9, 2014
Messages
5,463
Why would a list box list items that don't have record match?

And what happens when code runs? What would you like to happen?

Maybe you need:

If Me.MRN_Query.Form.RecordsetClone.NoMatch Then
MsgBox "No record"
Else
Me.Me.MRN_Query.Form.Bookmark = Me.MRN_Query.Form.RecordsetClone.Bookmark
End If

Also, remove the intentional error generator.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:33
Joined
May 7, 2009
Messages
19,229
just to simplify:
Code:
Private Sub List6_DblClick(Cancel As Integer)
On Error GoTo errhandler:
n = 1 / 0 ' cause an error
'Move to the record selected in the control

With Me.MRN_Query.Form.RecordsetClone
    .FindFirst "[Item] = '" & Me.List6.Value & "'"
    If .NoMatch Then
        Msgbox "No Record Found!"
    Else
        Me.MRN_Query.Form.Bookmark = .Bookmark
    End If
End With

Exit Sub
errhandler:
' error handling code
Resume Next
 

Users who are viewing this thread

Top Bottom