How do I end an on click???

mkelly

Registered User.
Local time
Yesterday, 18:31
Joined
Apr 10, 2002
Messages
213
This is the code I have on a form to open a reportt based on ehat is choosen in a list box....

Private Sub Command5_Click()
On Error GoTo Err_Command5_Click

If Text2 = "1" Then
DoCmd.OpenReport First_class_permit_report, acViewPreview, , , acWindowNormal

Else

If Text2 = "2" Then
DoCmd.OpenReport General_707 - 6 - 2, acViewPreview, , , acWindowNormal

Else

If Text2 = "3" Then
DoCmd.OpenReport Meter_Mail_Report, acViewPreview, , , acWindowNormal

Else

If Text2 = "4" Then
DoCmd.OpenReport nonprofit_permit_report, acViewPreview, , , acWindowNormal

Else

If Text2 = "5" Then
DoCmd.OpenReport precancelled_mail_permit_report, acViewPreview, , , acWindowNormal

Else

If Text2 = "6" Then
DoCmd.OpenReport pub_only_707 - 6 - 2, acViewPreview, , , acWindowNormal

Else

If Text2 = "7" Then
DoCmd.OpenReport Standard_mail_report, acViewPreview, , , acWindowNormal


Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

End If

End Sub

When I click the button I get an error of "Block If without End If"

What is the right command to end this??
 
Use a Case statement.....

Code:
Select Case Text2

Case Is = "1"
DoCmd.OpenReport First_class_permit_report, acViewPreview, , , acWindowNormal

Case Is  = "2"
'Do next thing

Case Else
MsgBox "Error in Your case Statement"

End select
 
While I, too, generally use the Select Case when there are more than a couple or three possibilities, the problem is that your End If needs to be above your error handing code, like this:

Code:
[B]End If[/B]

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

not below it, where you currently have it.
 
and ALSO note that you need an exit sub

otherwise you have

Code:
if conditiona then
   dosomething
else
    if conditionb then
        dosomething else
    else
         if conditionc then
             dosomethingelse
        end if
    end if
end if

[COLOR="Red"]EXIT SUB[/COLOR]

errorhandler
end sub

you see - if you DONT have the exit sub, your code just runsd, and then drops into the error handler EVERY time

note also that your error handler MUST have a RESUME statement.
 
Thanks for all the input but I am still confused I tried select but do not know how to start or stop it then I dont know if the exit sub is used with the Else IF or the Select.


Select Case (Text2)

Case Is = "1"
DoCmd.OpenReport First_class_permit_report, acViewPreview, , , acWindowNormal

Case Else

Case Is = "2"
DoCmd.OpenReport General_707 - 6 - 2, acViewPreview, , , acWindowNormal

Case Else

Case Is = "3"
DoCmd.OpenReport Meter_Mail_Report, acViewPreview, , , acWindowNormal

Case Else

Case Is = "4"
DoCmd.OpenReport nonprofit_permit_report, acViewPreview, , , acWindowNormal

Case Else

Case Is = "5"
DoCmd.OpenReport precancelled_mail_permit_report, acViewPreview, , , acWindowNormal

Case Else

Case Is = "6"
DoCmd.OpenReport pub_only_707 - 6 - 2, acViewPreview, , , acWindowNormal

Case Else

Case Is = "7"
DoCmd.OpenReport Standard_mail_report, acViewPreview, , , acWindowNormal


Case Else
MsgBox "Error in Your Case Statement"

End Select


Anyway nothing I am trying is working??? Anything easier? Thanks for everything so far...
 
You only need one Case Else, as the last case, Try this:

Code:
Select Case Me.Text2

Case "1"
DoCmd.OpenReport First_class_permit_report, acViewPreview, , , acWindowNormal

Case  "2"
DoCmd.OpenReport General_707 - 6 - 2, acViewPreview, , , acWindowNormal

Case  "3"
DoCmd.OpenReport Meter_Mail_Report, acViewPreview, , , acWindowNormal

Case  "4"
DoCmd.OpenReport nonprofit_permit_report, acViewPreview, , , acWindowNormal

Case "5"
DoCmd.OpenReport precancelled_mail_permit_report, acViewPreview, , , acWindowNormal

Case "6"
DoCmd.OpenReport pub_only_707 - 6 - 2, acViewPreview, , , acWindowNormal

Case "7"
DoCmd.OpenReport Standard_mail_report, acViewPreview, , , acWindowNormal

Case Else
MsgBox "Error in Your Case Statement"

End Select

Exit Sub
 

Users who are viewing this thread

Back
Top Bottom