No Data on Form Open

  • Thread starter Thread starter m stroup
  • Start date Start date
M

m stroup

I have the following code on a cmdButton

Dim strwhere As String
strwhere = "[tbl_Reports].[FltPhase] = '" & Me![cboPhase] & "'"
DoCmd.OpenForm "frm_MainView", acNormal, , strwhere
DoCmd.Close acForm, "frm_SearchPhase"

I would like to display a message "No data qualifies" and not open the form.
Not sure what the If statement should read.
 
M -

You can check to see if any records match before opening the form. Try
something like this:

If DCount("FltPhase","tbl_Reports","[FltPhase] = '" & Me![cboPhase] & "'") <
1 Then
msgbox "No records found"
Else
DoCmd.OpenForm "frm_MainView", acNormal, , strwhere
DoCmd.Close acForm, "frm_SearchPhase"
End If
 
Thanks Daryl,

I should have been able to figure a DCount out. Thanks for the help!

--
Teach me to fish! Thanks for the help.
Pax, M


Daryl S said:
M -

You can check to see if any records match before opening the form. Try
something like this:

If DCount("FltPhase","tbl_Reports","[FltPhase] = '" & Me![cboPhase] & "'") <
1 Then
msgbox "No records found"
Else
DoCmd.OpenForm "frm_MainView", acNormal, , strwhere
DoCmd.Close acForm, "frm_SearchPhase"
End If

--
Daryl S


m stroup said:
I have the following code on a cmdButton

Dim strwhere As String
strwhere = "[tbl_Reports].[FltPhase] = '" & Me![cboPhase] & "'"
DoCmd.OpenForm "frm_MainView", acNormal, , strwhere
DoCmd.Close acForm, "frm_SearchPhase"

I would like to display a message "No data qualifies" and not open the form.
Not sure what the If statement should read.
 
Back
Top