On no data please help...

L

Leif Hole

I have tried to use some code that I found in earlier postings but I cant
get it to work, I have tripple checked for spelling errors....

I use Access XP

Leif Hole, Norway

Here is what I use, from Joe Fallon:

This is a good way to handle the no data event for a report.
Note that the Print Preview button has to trap error 2501 when the code sets
Cancel=True.
====================================================
Private Sub Print_Preview_Click()
On Error GoTo Err_Print_Preview_Click

Dim DocName As String
DocName = [Forms]![Report Menu]![RptList]
DoCmd.OpenReport DocName, acViewPreview

Exit_Print_Preview_Click:
Exit Sub

Err_Print_Preview_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")
Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
Resume Exit_Print_Preview_Click
End Select

End Sub
====================================================
Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub
====================================================
 
L

Leif Hole

I still get the error message 2501 even when I trap it as in the code.
I dont get the msgbox as in the select case err.number...
Leif
SA said:
Leif:

What in particular is not working?
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

Leif Hole said:
I have tried to use some code that I found in earlier postings but I cant
get it to work, I have tripple checked for spelling errors....

I use Access XP

Leif Hole, Norway

Here is what I use, from Joe Fallon:

This is a good way to handle the no data event for a report.
Note that the Print Preview button has to trap error 2501 when the code sets
Cancel=True.
====================================================
Private Sub Print_Preview_Click()
On Error GoTo Err_Print_Preview_Click

Dim DocName As String
DocName = [Forms]![Report Menu]![RptList]
DoCmd.OpenReport DocName, acViewPreview

Exit_Print_Preview_Click:
Exit Sub

Err_Print_Preview_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")
Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
Resume Exit_Print_Preview_Click
End Select

End Sub
====================================================
Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub
====================================================
 
S

SA

Leif:

Looking again at the code, there is a problem with the error handler. It
should read:

Err_Print_Preview_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")
Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " & _
Err.Source & Chr(13) & Err.Description)
End Select
Resume Exit_Print_Preview_Click '<= This line moved down one line

--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg


Leif Hole said:
I still get the error message 2501 even when I trap it as in the code.
I dont get the msgbox as in the select case err.number...
Leif
SA said:
Leif:

What in particular is not working?
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

Leif Hole said:
I have tried to use some code that I found in earlier postings but I cant
get it to work, I have tripple checked for spelling errors....

I use Access XP

Leif Hole, Norway

Here is what I use, from Joe Fallon:

This is a good way to handle the no data event for a report.
Note that the Print Preview button has to trap error 2501 when the
code
sets
Cancel=True.
====================================================
Private Sub Print_Preview_Click()
On Error GoTo Err_Print_Preview_Click

Dim DocName As String
DocName = [Forms]![Report Menu]![RptList]
DoCmd.OpenReport DocName, acViewPreview

Exit_Print_Preview_Click:
Exit Sub

Err_Print_Preview_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")
Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
Resume Exit_Print_Preview_Click
End Select

End Sub
====================================================
Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub
====================================================
 
L

Leif Hole

I have tried the code you posted but it still dont trap the error 2501.

Leif Hole

Heres my exact code:

Private Sub cmdPrintSensur_Click()
On Error GoTo Err_cmdPrintSensur_Click

Dim frm As String

frm = "rptsensurliste"

DoCmd.OpenReport frm, acViewPreview

Exit_cmdPrintSensur_Click:
Exit Sub

Err_cmdPrintSensur_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")

Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)

End Select

Resume Exit_cmdPrintSensur_Click

End Sub

SA said:
Leif:

Looking again at the code, there is a problem with the error handler. It
should read:

Err_Print_Preview_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")
Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " & _
Err.Source & Chr(13) & Err.Description)
End Select
Resume Exit_Print_Preview_Click '<= This line moved down one line

--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg


Leif Hole said:
I still get the error message 2501 even when I trap it as in the code.
I dont get the msgbox as in the select case err.number...
Leif
SA said:
Leif:

What in particular is not working?
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg


I have tried to use some code that I found in earlier postings but I cant
get it to work, I have tripple checked for spelling errors....

I use Access XP

Leif Hole, Norway

Here is what I use, from Joe Fallon:

This is a good way to handle the no data event for a report.
Note that the Print Preview button has to trap error 2501 when the code
sets
Cancel=True.
====================================================
Private Sub Print_Preview_Click()
On Error GoTo Err_Print_Preview_Click

Dim DocName As String
DocName = [Forms]![Report Menu]![RptList]
DoCmd.OpenReport DocName, acViewPreview

Exit_Print_Preview_Click:
Exit Sub

Err_Print_Preview_Click:
Select Case Err.Number
Case 2501
MsgBox ("There is no data for this report.")
Case Else
MsgBox ("Error # " & Str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & Err.Description)
Resume Exit_Print_Preview_Click
End Select

End Sub
====================================================
Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub
====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top