Solved

Report_NoData run twice in  Access

Posted on 2006-10-22
22
694 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

733 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