Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Reports / Printing / April 2008

Tip: Looking for answers? Try searching our database.

Close label report if no data selected

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chuck - 19 Apr 2008 15:56 GMT
A97

I have a form with a command button to open a label report

The label report is based on a query.  If the result of the query has no data
because the criteria was not met, how can I prevent the label report from
opening?

The label report module has the following statements:

Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
On Error GoTo Err_Detail_Print

    (Snip special formatting)

Err_Detail_Print:
   MsgBox "No Labels Selected To Print", vbOKOnly, "Label Selection Problem"
   DoCmd.Close acDefault, acSaveNo
   Exit Sub
End Sub

The message box opens,  I click OK, The message box closes and the report
opens.  The three fields (name, address, city-state-zip) all show #ERROR.
This doesn't hurt anything, it just looks bad.  I would like the report to not
open at all and the focus go back the form with the command button to open the
report.

I have tried:   DoCmd.Close acReport, "Avery 8160 Labels", acSaveNo
This produced an error message:  This action can not be carried out while
processing a form or report event

Chuck
fredg - 19 Apr 2008 17:39 GMT
> A97
>
[quoted text clipped - 28 lines]
>
> Chuck

This is what the report's OnNoData event is for.
You can get rid of your Detail_Print code.

Code the Report's OnNoData event:

MsgBox "No records were found."
Cancel = True

The above will raise an error if the report was opened from code,
so...
Also, code the form command button event that is used to open the
report:

On Error GoTo Err_Handler
DoCmd.OpenReport "YourReport", acViewPreview

Exit_Sub:
    Exit Sub
Err_Handler:
    If Err = 2501 Then
    Else
        MsgBox "Error #: " & Err.Number & " " & err.Desription
    End If
    Resume Exit_Sub
   
Signature

Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

Chuck - 19 Apr 2008 23:57 GMT
Thank you Fred.  Works perfectly.

Chuck

>> A97
>>
[quoted text clipped - 53 lines]
>    End If
>    Resume Exit_Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.