Cancelling a report - again!

L

Leslie Isaacs

Hello All

I thuoght I had the answer to this from an earlier post (thank you Jeff
Conrad), but in trying to adapt it for my purpose I still get an error
'Duplicate declaration in current scope' with my second line of
"Err_Command677_Click:" highlighted - but I can't see what to do!
..
The problem is trying to handle the no-data error for two reports at the
same time. The code I have is:

Private Sub Command677_Click()
On Error GoTo Err_Command677_Click

Dim stDocName As String

If MsgBox("Do you want to print the Portrait version", vbYesNo + vbQuestion,
"WARNING") = vbNo Then
stDocName = "rpt P60 try 2004/05"
DoCmd.OpenReport stDocName, acPreview

stDocName = "rpt P60 try 2004/05 dcmonths"
DoCmd.OpenReport stDocName, acPreview

Err_Command677_Click:
If Err.number = 2501 Then
Resume Next
Else
'MsgBox Err.Description
End If

Else
stDocName = "rpt P60 try 2004/05 portrait"
DoCmd.OpenReport stDocName, acPreview

stDocName = "rpt P60 try 2004/05 portrait dcmonths"
DoCmd.OpenReport stDocName, acPreview

Err_Command677_Click:
If Err.number = 2501 Then
Resume Next
Else
'MsgBox Err.Description
End If

End If

Exit_Command677_Click:
Exit Sub

Resume Exit_Command677_Click
End Sub

Hope someone can help.
Many thanks
Leslie Isaacs
 
S

SusanV

You have Err_Command677_Click: twice in the same function, which is not
allowed. Change one of them and the error handling that points to it and you
should be good to go.
 
J

Jeff Conrad

in message:
Hello All

I thuoght I had the answer to this from an earlier post (thank you Jeff
Conrad), but in trying to adapt it for my purpose I still get an error
'Duplicate declaration in current scope' with my second line of
"Err_Command677_Click:" highlighted - but I can't see what to do!
.
The problem is trying to handle the no-data error for two reports at the
same time. The code I have is:

<code snipped>

Leslie,

Access is confused with the duplicate declarations.

Replace your existing code with this:

'************Code Start*************
Private Sub Command677_Click()
On Error GoTo Err_Command677_Click

Dim strDocName As String

If MsgBox("Do you want to print the Portrait version", _
vbYesNo + vbQuestion, "WARNING") = vbNo Then
' Print portrait versions
strDocName = "rpt P60 try 2004/05"
DoCmd.OpenReport strDocName, acPreview

strDocName = "rpt P60 try 2004/05 dcmonths"
DoCmd.OpenReport strDocName, acPreview
Else
' Print landscape versions
strDocName = "rpt P60 try 2004/05 portrait"
DoCmd.OpenReport strDocName, acPreview

strDocName = "rpt P60 try 2004/05 portrait dcmonths"
DoCmd.OpenReport strDocName, acPreview
End If

Exit_Command677_Click:
Exit Sub

Err_Command677_Click:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description
End If
Resume Exit_Command677_Click

End Sub
'************Code End*************
 

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