No Data on Form Open

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.
 
A

Alex Dybenko

Hi,
you can check recordset count on form's open event, and cancel it:


if Me.Recordset.RecordCount =0 then
Cancel=true
end if

DoCmd.OpenForm in that case will produce runtime error which you have to
handle

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 
D

Daryl S

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
 
M

m stroup

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top