Solved

Report_NoData run twice in  Access

Posted on 2006-10-22
22
673 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

911 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

25 Experts available now in Live!

Get 1:1 Help Now