microsoft access search macro
microsoft access search macro
(OP)
In access i have the macro "requery", that searches for a program name using the description for that program name. The problem is that when you type in a word that cant be found in the description, the form goes blank. How can fix it so that a message comes up and says "there are no matches"?





RE: microsoft access search macro
Essentially, you need an if statement somewhere in your loop that searches for the file name.
CODE
(statements that result in pulling the form)
Else 'i.e. no match is found
MsgBox "No matches were found."
Exit Sub 'This kills the macro.
'You could also try a "Goto" or "Exit Do" to take you to a point in your code.
End If
If you post your actual macro, we might could give you a piece of code that you can copy and paste.
There are several options with a message box, for instance, you could get it to pop up an input box saying "No matches found for {your search string}. Search again for: {input box for you to input corrected search string}" with option buttons "OK" and "Cancel" where "OK" searches again while "Cancel" gets you out of the loop/macro.
RE: microsoft access search macro
CODE
(code statements)
Exit Sub 'So that normal operation does not invoke the Msgbox command
LineName: Msgbox "No match was found."
End Sub
RE: microsoft access search macro
Private Sub SEARCH_Click()
Private Sub cmdSearch_Click()
DoCmd.FindRecord , , acNext
Exit_SEARCH_Click:
Exit Sub
Err_SEARCH_Click:
MsgBox Err.Description
Resume Exit_SEARCH_Click
End Sub
RE: microsoft access search macro
RE: microsoft access search macro
As far as I know, the only way to print a message box when no record is found is to complicate your code by first checking the field to see if a record exists and then only calling that record if it exists - else displaying the message box.
Unfortunately, it's been so long since I've written VB for Access ('99) that I have no idea how to do that anymore!