By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,234 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,234 IT Pros & Developers. It's quick & easy.

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

anoble1
100+
P: 223
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFind_Click()
  2. On Error GoTo errHandle
  3. Dim records As Recordset
  4.     If Nz(txtPOSearch.value, "") = "" Then
  5.         Forms!frmMain!frmAll.Form.Filter = "tblInformation.PO = 0"
  6.         Forms!frmMain!frmAll.Form.FilterOn = True
  7.  
  8.     ElseIf records.EOF Then Exit Sub
  9.  
  10.  
  11.     Else
  12.         'If Not Me.Recordset.EOF Then Exit Sub
  13.         Forms!frmMain!frmAll.Form.Filter = "tblInformation.PO = " & txtPOSearch.value
  14.         Forms!frmMain!frmAll.Form.FilterOn = True
  15.     End If
  16.  
  17.     Exit Sub
Sep 28 '17 #1

✓ answered by NeoPa

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.RecordCount of the SubForm to see if it's greater than zero (0).

Share this Question
Share on Google+
1 Reply


NeoPa
Expert Mod 15k+
P: 31,419
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.RecordCount of the SubForm to see if it's greater than zero (0).
Sep 28 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.