Msgbox needed for search with no results

L

LyndsyJo

From a switchboard, users click a button (based on a macro, which is based on
a parameter query) to search for a keyword or item number in my database.
The results are displayed in a form. When their search yields no matches,
the result is just the blank form background.

I'm trying to modify the macro to provide the user with a Msgbox that will
say "No items match your search criteria". I know that I need to type
something in the Conditions of the macro, but that's where I'm stuck. The
best I can come up with, based on other questions in this discussion group, is

Forms![Apparel]![StyleNumber] <> [Search for apparel by style
number]![StyleNumber]

but I know that the 2nd part is invalid and causing an error message. The
first part is the form that displays the search results. The 2nd part is the
parameter query that the macro is based on. What am I doing wrong?

Please let me know if more information is needed. Be gentle if your answer
has to do with Visual Basic code, as I probably know more about nuclear
physics than I do about Visual Basic. Thanks in advance.
 
J

jahoobob via AccessMonster.com

I'm assuming the macro opens the results form. Try this code on the OnClick
of the button instead of the macro:
Private Sub Your ButtonName_Click()
If DCount("*", "[YourQuery]") < 1 Then
MsgBox ("No items match your search criteria.")
Exit Sub
End If
Dim stDocName As String
stDocName = "YourResultsForm"
DoCmd.OpenForm stDocName
End Sub
From a switchboard, users click a button (based on a macro, which is based on
a parameter query) to search for a keyword or item number in my database.
The results are displayed in a form. When their search yields no matches,
the result is just the blank form background.

I'm trying to modify the macro to provide the user with a Msgbox that will
say "No items match your search criteria". I know that I need to type
something in the Conditions of the macro, but that's where I'm stuck. The
best I can come up with, based on other questions in this discussion group, is

Forms![Apparel]![StyleNumber] <> [Search for apparel by style
number]![StyleNumber]

but I know that the 2nd part is invalid and causing an error message. The
first part is the form that displays the search results. The 2nd part is the
parameter query that the macro is based on. What am I doing wrong?

Please let me know if more information is needed. Be gentle if your answer
has to do with Visual Basic code, as I probably know more about nuclear
physics than I do about Visual Basic. Thanks in advance.
 
L

LyndsyJo

There's already something in the OnClick event of my switchboard button. Not
something I put in, but by the Switchboard Manager. It's

=HandleButtonClick(1)

Can you put two things in an event? Or do you have any other suggestions?
Thanks!



jahoobob via AccessMonster.com said:
I'm assuming the macro opens the results form. Try this code on the OnClick
of the button instead of the macro:
Private Sub Your ButtonName_Click()
If DCount("*", "[YourQuery]") < 1 Then
MsgBox ("No items match your search criteria.")
Exit Sub
End If
Dim stDocName As String
stDocName = "YourResultsForm"
DoCmd.OpenForm stDocName
End Sub
From a switchboard, users click a button (based on a macro, which is based on
a parameter query) to search for a keyword or item number in my database.
The results are displayed in a form. When their search yields no matches,
the result is just the blank form background.

I'm trying to modify the macro to provide the user with a Msgbox that will
say "No items match your search criteria". I know that I need to type
something in the Conditions of the macro, but that's where I'm stuck. The
best I can come up with, based on other questions in this discussion group, is

Forms![Apparel]![StyleNumber] <> [Search for apparel by style
number]![StyleNumber]

but I know that the 2nd part is invalid and causing an error message. The
first part is the form that displays the search results. The 2nd part is the
parameter query that the macro is based on. What am I doing wrong?

Please let me know if more information is needed. Be gentle if your answer
has to do with Visual Basic code, as I probably know more about nuclear
physics than I do about Visual Basic. Thanks in advance.
 
J

jahoobob via AccessMonster.com

How is the keyword entered? A form? If it is a form then there is probably
a Search button on that form. The code goes there.
There's already something in the OnClick event of my switchboard button. Not
something I put in, but by the Switchboard Manager. It's

=HandleButtonClick(1)

Can you put two things in an event? Or do you have any other suggestions?
Thanks!
I'm assuming the macro opens the results form. Try this code on the OnClick
of the button instead of the macro:
[quoted text clipped - 28 lines]
 
L

LyndsyJo

The keyword is entered by clicking on the button on the switchboard. There
is no search button on the form.

jahoobob via AccessMonster.com said:
How is the keyword entered? A form? If it is a form then there is probably
a Search button on that form. The code goes there.
There's already something in the OnClick event of my switchboard button. Not
something I put in, but by the Switchboard Manager. It's

=HandleButtonClick(1)

Can you put two things in an event? Or do you have any other suggestions?
Thanks!
I'm assuming the macro opens the results form. Try this code on the OnClick
of the button instead of the macro:
[quoted text clipped - 28 lines]
has to do with Visual Basic code, as I probably know more about nuclear
physics than I do about Visual Basic. Thanks in advance.
 

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