How to send messagebox if item is not listed in data and exit?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anoble1
    New Member
    • Jul 2008
    • 246

    How to send messagebox if item is not listed in data and exit?

    I am having a hard time for some reason. I have a search textbox with a button to search. Right now if you put some bogus number in there is returns a value that is not the correct value. Works fine if you type in the correct value though.
    Anyway how do you say if the value you entered is not the records then Exit Sub and send messagbox? And do you put that at the very end of the IF statement?

    Here is what I have that is not working.

    Code:
    Private Sub cmdFind_Click()
    On Error GoTo errHandle
    Dim records As Recordset
        If Nz(txtPOSearch.value, "") = "" Then
            Forms!frmMain!frmAll.Form.Filter = "tblInformation.PO = 0"
            Forms!frmMain!frmAll.Form.FilterOn = True
                
        ElseIf records.EOF Then Exit Sub
        
        
        Else
            'If Not Me.Recordset.EOF Then Exit Sub
            Forms!frmMain!frmAll.Form.Filter = "tblInformation.PO = " & txtPOSearch.value
            Forms!frmMain!frmAll.Form.FilterOn = True
        End If
        
        Exit Sub
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Certainly a hard time explaining your problem clearly. Can I assume you have a SubForm called frmAll and you want to see if there are any records on it? Also, that you want the SubForm to reflect filtering based on some field that isn't clear matching the value from a control on your main form?

    If so, then general principles as working with very little info :
    1. Build the form with a SubForm linked on the main form's control (called [txtPOSearch] I suspect).
    2. Check the .Recordset.Reco rdCount of the SubForm to see if it's greater than zero (0).

    Comment

    Working...