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

Query returned no results-how to display in form not pop-up msg box

P: n/a
kev
Hi Folks,

I have created a search query in which it successfully returns correct
results. When there are no records returned, instead of giving out a
blank form i created a pop-up msg which is attached to the On Open
event.
However, right after the msg box pops saying"no records", this is
followed by another msg box with "TheOpen Form action was cancelled".

Is there a way i can eliminate the second msg box from appearing?

Or is there another approach in which i want a form to display the
message someting like below:

Your search on (search criteria) returned no results.
what i need is something like when there is matching records, open form
"a" and if there is no records open form"b" stating Your search on
(search criteria) returned no results.
Pls help.

Thanks.

Jan 17 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a


On Jan 17, 1:58 am, "kev" <kevi....@gmail.comwrote:
Hi Folks,

I have created a search query in which it successfully returns correct
results. When there are no records returned, instead of giving out a
blank form i created a pop-up msg which is attached to the On Open
event.
However, right after the msg box pops saying"no records", this is
followed by another msg box with "TheOpen Form action was cancelled".

Is there a way i can eliminate the second msg box from appearing?

Or is there another approach in which i want a form to display the
message someting like below:

Your search on (search criteria) returned no results.

what i need is something like when there is matching records, open form
"a" and if there is no records open form"b" stating Your search on
(search criteria) returned no results.

Pls help.

Thanks.
In the code module that calls the open form a, you need to trape for
error 2501 and resume next. (Error 2501 is "The Open Form event was
cancelled")

Jan 17 '07 #2

P: n/a
kev
Hi,

i am not sure on how to trap the error . below i provide the coding for
both:
a) the first search form
Private Sub cmdSearch_Click()
On Error GoTo Err_cmdSearch_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "statusall"

stLinkCriteria = "[WWID]=" & "'" & Me![WWID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdSearch_Click:
Exit Sub

Err_cmdSearch_Click:
MsgBox Err.Description
Resume Exit_cmdSearch_Click

End Sub

b) on open event in the second form
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "There are no records to display at this time." _
, vbInformation, "No Records"
Cancel = True
End If
End Sub

Can you please provide me the coding and tell me d exact location to
place it?

Thanks.
rq******@sympatico.ca wrote:
On Jan 17, 1:58 am, "kev" <kevi....@gmail.comwrote:
Hi Folks,

I have created a search query in which it successfully returns correct
results. When there are no records returned, instead of giving out a
blank form i created a pop-up msg which is attached to the On Open
event.
However, right after the msg box pops saying"no records", this is
followed by another msg box with "TheOpen Form action was cancelled".

Is there a way i can eliminate the second msg box from appearing?

Or is there another approach in which i want a form to display the
message someting like below:

Your search on (search criteria) returned no results.

what i need is something like when there is matching records, open form
"a" and if there is no records open form"b" stating Your search on
(search criteria) returned no results.

Pls help.

Thanks.

In the code module that calls the open form a, you need to trape for
error 2501 and resume next. (Error 2501 is "The Open Form event was
cancelled")
Jan 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.