By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,827 Members | 2,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,827 IT Pros & Developers. It's quick & easy.

Message if no record found

P: n/a
jpr
Hello,

I have developed a search form with a txtbox and a cmdbutton to open a
form based on a query.

The cmdbutton opens a form if the record is found. Can anyone help me
with VBA to display a No Record Found message?

THis is what I have on the OnClick Event of the button:

If IsNull(Me.txtsearch) Then
DoCmd.CancelEvent
Else
DoCmd.OpenForm "myform", acNormal, "myquery", "", , acNormal
DoCmd.Echo True, ""
End If

Note that the query behind the form has following in the criteria in
the LName field:
like [forms]![welcome]![txtsearch]

Thank you.

Jan 11 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 11 Jan 2007 02:56:55 -0800, "jpr" <jp***@tin.itwrote:

In myform's Form_Open write:
If Me.RecordsetClone.RecordCount = 0 then
Msgbox "Boo-hoo, no records!"
Cancel = True
end if

You may have to move this code to Form_Load if it doesn't work. If so,
change the third line to:
DoCmd.Close Me.Name, acForm

-Tom.

>Hello,

I have developed a search form with a txtbox and a cmdbutton to open a
form based on a query.

The cmdbutton opens a form if the record is found. Can anyone help me
with VBA to display a No Record Found message?

THis is what I have on the OnClick Event of the button:

If IsNull(Me.txtsearch) Then
DoCmd.CancelEvent
Else
DoCmd.OpenForm "myform", acNormal, "myquery", "", , acNormal
DoCmd.Echo True, ""
End If

Note that the query behind the form has following in the criteria in
the LName field:
like [forms]![welcome]![txtsearch]

Thank you.
Jan 11 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.