My Assistant
![]() ![]() |
|
|
Dec 10 2008, 08:59 AM
Post
#1
|
|
|
UtterAccess Veteran Posts: 479 |
I'm using the AfterUpdate event on a combo box in a form to open a report (using the combo box to establish my filter for the report). The report has some code in the On No Data event to pop a message box that says "No Data to Report for that Timeframe" and Cancel=True. Trouble is that because I'm using the DoCmd.OpenReport from the form, I still get an error message saying the OpenReport was cancelled. Any way to suppress that?
|
|
|
|
Dec 10 2008, 09:06 AM
Post
#2
|
|
|
UtterAccess VIP Posts: 9,209 From: Maryland |
Rather then use the On No Data Event, I would use the OnActivate event with the following code:
CODE Dim strMsg As String Dim strTitle As String strMsg = "No Records Returned" strTitle = "No Records Returned" If Me.Report.HasData Then Exit Sub Else MsgBox strMsg, vbOKOnly + vbExclamation, strTitle DoCmd.close acReport, Me.Name End If On your form where you are opening the report use: CODE DoCmd.OpenReport RptName, acViewPreview HTH. |
|
|
|
Dec 10 2008, 09:13 AM
Post
#3
|
|
|
UtterAccess Veteran Posts: 479 |
Thanks.
|
|
|
|
Dec 10 2008, 09:40 AM
Post
#4
|
|
|
UtterAccess Editor Posts: 15,970 From: Northern Virginia, USA |
Another approach is to continue to use the OnNoData event (which is my preference (IMG:http://www.utteraccess.com/forum/style_emoticons/default/sad.gif) ) ... and just suppress the error prior to the DoCmd.OpenReport ...
On Error Resume Next DoCmd.OpenReport ..... .. If the DoCmd.OpenReport is NOT the last line of code before the End Sub / Exit Sub, then I reset the error handler ... On Error Goto 0 (Turns OFF error handling) ... Or ... On Error Goto ErrorHandlerLabel |
|
|
|
Dec 10 2008, 09:45 AM
Post
#5
|
|
|
UtterAccess Veteran Posts: 479 |
Thanks for that approach as well, good for future reference.
|
|
|
|
Dec 10 2008, 12:04 PM
Post
#6
|
|
|
UtterAccess Editor Posts: 15,970 From: Northern Virginia, USA |
You're welcome! ....
One BIG important note ... the OnActivate event DOES NOT FIRE if you print directly to the printer ... so ... if you do NOT Preview the report, the OnActivate will NOT fire .... thus my reason for sticking with the OnNoData. (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 08:46 PM |