Message Box

  • Thread starter Thread starter TheCaptain
  • Start date Start date
T

TheCaptain

Hey,

I have a form that the user enters search parameters into. After pressing
the search button, they get the results in a new form. If there is no data
that the user searched for, is there a way to create a message box that says
something like "Please revise your search" and then have a button that will
take the user back to the search form?

Thanks in advance
Ethan
 
Private Sub SomeButton_Click()
Dim strID As String
strID = Nz(DLookup("[ID]", "[TableName]", "[SomeField] =""" & _
Form!txtSomeFormControl), "0")
Dim msg, style, title, ctext, responce, mystring
Dim stDocName As String
Dim stLinkCriteria As String
If strID = "0" Then
msg = "Please revise your search" & vbCrLf & vbCrLf & "Do you want
to search again?"
style = vbYesNo
title = "No Record Found"
responce = MsgBox(msg, style, title)
If responce = vbYes Then
Me.SomeFormControl.SetFocus
Else
'Do something else here
End If
End If
End Sub
 
Thanks Ken, very simple and works like a charm!

KenSheridan via AccessMonster.com said:
Ethan:

You don't really need to open the second form at all if the search produces
no results. Make the opening of the second form conditional. Just how you
do that depends on how the second form is being filtered. If its based on a
query which references the controls on the first form as parameters:

Const conMESSAGE = _
"No records found. Please revise your search."

If DCount("*", "YourQuery") > 0 Then
DoCmd.OpenForm "YourSecondForm"
Else
MsgBox conMESSAGE, vbInformation, "Warning"
End If

If the second form is based on an a table or unrestricted query and is being
filtered by means of the WhereCondition argument of the OpenForm method:

Const conMESSAGE = _
"No records found. Please revise your search."

Dim strCriteria As String

strCriteria = <get filter expression from somewhere>

If DCount("*", "YourTableOrQuery", strCriteria) > 0 Then
DoCmd.OpenForm "YourSecondForm", WhereCondition:=strCriteria
Else
MsgBox conMESSAGE, vbInformation, "Warning"
End If

Ken Sheridan
Stafford, England
 
Back
Top