Messages in Access - Suppress or Replace - Access 2k, DAO

  • Thread starter Thread starter Leonard Priestley
  • Start date Start date
L

Leonard Priestley

I have been designing reports and have made provision for queries that
return no data. If this occurs, I provide a user-friendly message advising
the user. When I try this out, I also get a message from Access saying "The
OpenForm Action was cancelled". I don't want this message to appear, or
would like to modify it, because I don't think the user will have any idea
what the 'OpenForm Action' is. How can I suppress the unwanted message or
replace it with one I prefer?

Leonard Priestley
 
hai,

If u want the property details that means buying & selling or guest
house and what ever in property just login the side www.getinnet.com
you will get all the details in this side it will be useful to you. go
ahead.

Not only real estate
Web Design
Web Hosting
Real Estate
Automobile
 
Leonard put the following code in your report NODATA event

Private Sub Report_NoData(Cancel As Integer)
Beep
MsgBox "No records match the criteria you entered.", vbExclamation, "No
Records Found"
Cancel = True
End Sub

A report is called from a form and is displayed as Print preview, Printed,
or sent as an email depending on the user's choice. If there is not data a
msgbox is displayed with the above message. The user clicks OK and then can
make another choice.
 
Allan Murphy,

Thank you for your reply. Essentially, my code already looks the same as
your suggestion. That is, I am using the NODATA event, providing a message
and setting Cancel = True. My problem is that after displaying my message,
and cancelling the event, Access displays a further message - "OpenForm
Action was cancelled", which I don't want. I know that in the case of an
input mask error it is possible to use acDataErrContinue to tell the program
to keep going and not show its message. The code looks like this:

Private Sub Form_Error (DataErr As Integer, Response As Integer)
Const INPUTMASK_VIOLATION = 2279
If DataErr = INPUTMASK_VIOLATION Then
MsgBox "There was an input mask violation!"
Response = acDataErrContinue
End If
End Sub

What I am trying to find out is how to do the same with this darned
"OpenForm Action was Cancelled " message. I am assuming that cancelling the
report doesn't qualify as an Error event.

Regards
Leonard Priestley
 
Leonard

Remove the Cancel=true from your NODATA event in your report. I had the same
problem.
 
How are you calling the report? If you are just letting
the user double click on the report list, you don't
have much choice.

(david)
 
the error message occurs because you cancel the OpenReport action in the
NoData event procedure, but it occurs *in* the procedure that runs the
OpenReport action. standard procedure is to either 1) check for records
*before* running the action, or 2) trap the "action cancelled" error and
handle it.

to do number 1: you can use a DCount function in your code before the
OpenReport action to check for records returned by the query underlying the
report, as

If DCount(1, "MyQueryName") > 0 Then
DoCmd.OpenReport "MyReportName"
Else
MsgBox "No data available."
End If

to do number 2: add error handling code to the procedure that runs the
OpenReport action, as

On Error GoTo OpenReport_Err

DoCmd.OpenReport "MyReport"

OpenReport_End:
Exit Sub

OpenReport_Err:
If Err.Number = 2501 Then
Resume OpenReport_End
Else
MsgBox Err.Number & " " & Err.Description
End If

hth
 
Alan,

Thank you for your suggestion. Unfortunately it doesn't exactly solve the
problem for me. When I remove the cancel = True it does stop the offending
message, but the message I want delivered does not disappear until the OK
button has been clicked twice (message is coming up a second time, maybe?).
In addition, the blank report appears afterward. No report appears if I
leave the Cancel = True in the code.

Leonard Priestley
 
Yes, thank you Tina,
I have used your first suggestion and have the result I wanted.
Have a Nice Day
Leonard
 
Back
Top