Solved

Report_NoData run twice in  Access

Posted on 2006-10-22
22
702 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 6
  • 5
  • +1
22 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
 

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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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 …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

717 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