Solved

Report_NoData run twice in  Access

Posted on 2006-10-22
22
663 Views
Last Modified: 2008-02-20
hi sir i  have this code for a button on form that will run a report for me ,
now every time
i press the button it will run Report_NoData sub rotuien massage  twice  and it will open an empty  report
the report code is
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for this report", _
           vbInformation + vbOKOnly, "Information"
    Cancel = -1
End Sub
and the button code is

Private Sub btnStatusReport_Click()
On Error GoTo Err_btnStatusReport_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
   
      'Open the report
    stDocName = "Status History Report"
    If Not IsNull(Me.TypeDetailsID) Then
    stLinkCriteria = "[TypeDetailsID]=" & Me![TypeDetailsID]

    DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
   Me.Refresh
    Else
    MsgBox "You Should Enter Type Name", vbCritical
    Me.CobType.SetFocus
       
    End If
 
Exit_btnStatusReport_Click:
    Exit Sub

Err_btnStatusReport_Click:
    MsgBox Err.Description
    Resume Exit_btnStatusReport_Click
   
End Sub
 how can prevent the report from preview  and prevent the massage to popup twice i need it only one

 
0
Comment
Question by:osama120
  • 10
  • 6
  • 5
  • +1
22 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 17786322


try this


Private Sub Report_NoData(Cancel As Integer)

Stop     '<<<< Add this for testing

MsgBox "There is no data for this report", _
           vbInformation + vbOKOnly, "Information"
    Cancel = -1
End Sub

the code will stop in the Stop when there is nodata for the report.

to continue running the codes step by step  press F8 until you find where the second message is coming from



0
 

Author Comment

by:osama120
ID: 17786340
it give me  run time error 2501
the open report was cancelled then it will mark
DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
0
 

Author Comment

by:osama120
ID: 17786342
the open report action  was cancelled then it will mark
0
 
LVL 9

Expert Comment

by:mpmccarthy
ID: 17786343
Replace acViewPreview with acViewNormal.  This will send the report directly to the printer without previewing it.

DoCmd.OpenReport stDocName, acViewNormal, , stLinkCriteria
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 17786347


Private Sub Report_NoData(Cancel As Integer)

MsgBox "There is no data for this report", _
           vbInformation + vbOKOnly, "Information"
    Cancel = -1

Stop     '<<<< Add this for testing   move here

End Sub
0
 

Author Comment

by:osama120
ID: 17786367
the will make loop againand again and it still mark the line
DoCmd.OpenReport stDocName, acViewNormal, , stLinkCriteria
0
 
LVL 9

Expert Comment

by:mpmccarthy
ID: 17786381
Remove the Refresh from below the open report command
0
 
LVL 9

Expert Comment

by:mpmccarthy
ID: 17786385
Have you by any chance got a subReport on the report?
0
 

Author Comment

by:osama120
ID: 17786394
no
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 17786395
do a Debug>Compile

fix any error that may arise

then do a Compact and Repair of the database
0
 

Author Comment

by:osama120
ID: 17786399
the error still there and it break the code
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:osama120
ID: 17786410
if i remove the code
Private Sub Report_NoData(Cancel As Integer)

MsgBox "There is no data for this report", _
           vbInformation + vbOKOnly, "Information"
    Cancel = -1
End Sub
 it will show an empty preview report
0
 
LVL 9

Expert Comment

by:mpmccarthy
ID: 17786412
Did removing the refresh make any difference?
0
 
LVL 9

Expert Comment

by:mpmccarthy
ID: 17786416
Is there code in the On format event of the report or any code behind the report at all?
0
 

Author Comment

by:osama120
ID: 17786419
no it make no difference
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 17786425


try this

Private Sub btnStatusReport_Click()
'On Error GoTo Err_btnStatusReport_Click
On error resume next

    Dim stDocName As String
    Dim stLinkCriteria As String
   
      'Open the report
    stDocName = "Status History Report"
    If Not IsNull(Me.TypeDetailsID) Then
    stLinkCriteria = "[TypeDetailsID]=" & Me![TypeDetailsID]

    DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
   Me.Refresh
    Else
    MsgBox "You Should Enter Type Name", vbCritical
    Me.CobType.SetFocus
       
    End If
 
'Exit_btnStatusReport_Click:
'    Exit Sub

'Err_btnStatusReport_Click:
'    MsgBox Err.Description
'    Resume Exit_btnStatusReport_Click
 

    If Err = 2501 Then Err.Clear
   
End Sub

   place the nodata code back in the report open event

0
 

Author Comment

by:osama120
ID: 17786430
still the same
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 17786532
did you do this?

do a Debug>Compile

fix any error that may arise

then do a Compact and Repair of the database
0
 

Author Comment

by:osama120
ID: 17786565
if i pree the button it will give me
Run Time Error:'2501'
the OpenReport Action was cancelled
then i press Debug then
it will givea yellow mark on the line
 DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
then i have to reset  
0
 

Author Comment

by:osama120
ID: 17786566
by the way if i move the mouse  on acViewPreview it will show number 2
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17786879
Because the cancel flag is set to True, it returns error number 2501, therefore because u use error handlers, uneed to cater for it

one way is modifying Err_btnStatusReport_CLick

e.g.


Err_btnStatusReport_Click:
    If err.Number <> 2501 then MsgBox Err.Description
    Resume Exit_btnStatusReport_Click
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 17787864

so you don't get two messages

Exit_btnStatusReport_Click:
    Exit Sub


Err_btnStatusReport_Click:
     '    MsgBox Err.Description
     Resume Exit_btnStatusReport_Click
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now