Need Help with "Search" code (1 Viewer)

jdp103

Registered User.
Local time
Today, 12:43
Joined
Sep 26, 2003
Messages
46
I have a button on a form to search for a document by a number that the user inputs. It works great as far as finding the correct document, but the problem is that if there is no match, it automatically opens up a new blank document. I have tried all different error messages, etc. and can't figure out how to have it just give a message that says "Record not found" and just exit sub. Here is the code....can anyone help??

Private Sub Command12_Click()

Dim stDocName As String
Dim stLinkCriteria As String
Dim stInput As String

stInput = InputBox("Enter CPR/Task Number to Find", "Search for CPR/Task")
stDocName = "Business Requirement Document"
stLinkCriteria = "[BRD Number]=" & stInput

DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub
 

FoFa

Registered User.
Local time
Today, 11:43
Joined
Jan 29, 2003
Messages
3,672
WHen the filter filters out all the data, the only left for the form is a new screen. You could run a dcount of the criteria before you issue the open form, and if it returns < 1 do not open the form and issue a msg saying no records found try again. Or in the form itself you could check the returned recordset to see if it contains anything, and if not handle it there.
 

jdp103

Registered User.
Local time
Today, 12:43
Joined
Sep 26, 2003
Messages
46
Thanks! I'll try that!
 

Users who are viewing this thread

Top Bottom