If, Then Button Code

M

Michael Firey

I use a button on a form to run a report. I now want to use the
button to run a choice of reports based on what the clientID field
value is. For example, if the clientID field is 866, I want it to run
a report called FireytechWO. If the clientID field value is 845, I
want it to run a report called NewcorpWO. Below is the code I
currently use for the button. What do I need to do to make the code
run the above choices?

Private Sub FireytechWO_Click()
On Error GoTo Err_FireytechWO_Click
If Me.Dirty Then Me.Dirty = False
If Me.Dirty Then RunCommand acCmdSaveRecord
Dim strDocName As String
Dim strWhere As String
strDocName = "FireytechWO"
strWhere = "[ticketnumber] = " & "" & Me.TicketNumber & ""
DoCmd.OpenReport strDocName, acPreview, , strWhere

Exit_FireytechWO_Click:
Exit Sub

Err_FireytechWO_Click:
MsgBox Err.Description
Resume Exit_FireytechWO_Click
End Sub
 
B

Bob Quintal

m:
I use a button on a form to run a report. I now want to use the
button to run a choice of reports based on what the clientID field
value is. For example, if the clientID field is 866, I want it to
run a report called FireytechWO. If the clientID field value is
845, I want it to run a report called NewcorpWO. Below is the
code I currently use for the button. What do I need to do to make
the code run the above choices?

Private Sub FireytechWO_Click()
On Error GoTo Err_FireytechWO_Click
If Me.Dirty Then Me.Dirty = False
If Me.Dirty Then RunCommand acCmdSaveRecord
Dim strDocName As String
Dim strWhere As String
strDocName = "FireytechWO"
strWhere = "[ticketnumber] = " & "" & Me.TicketNumber & ""
DoCmd.OpenReport strDocName, acPreview, , strWhere

Exit_FireytechWO_Click:
Exit Sub

Err_FireytechWO_Click:
MsgBox Err.Description
Resume Exit_FireytechWO_Click
End Sub
replace the one line strDocName = "FireytechWO"
with a case structure

Select Case ClientId
Case 845
strDocName = "NewcorpWO"
Case 866
strDocName = "FireytechWO"
case else
strDocName = "GenericWO"
end case
 

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