Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional print button 1

Status
Not open for further replies.

Chummly66

MIS
Feb 19, 2005
106
US
Hello folks!

I currently have a print button that will print a "invoice" (actually a report) when I click a button on my form for that particular record. Here is the code for that:

On Error GoTo Err_btnWorkOrder_Click

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.Newrecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "Work Order", acViewNormal, , strWhere
End If

Exit_btnWorkOrder_Click:
Exit Sub

Err_btnWorkOrder_Click:
MsgBox Err.Description
Resume Exit_btnWorkOrder_Click

But now I have three different reports, and I need the form to select one of the reports based on data entered on the form.

I have two fields on my form: cboStoreID and txtCharge. What I need to do, is this.

If the cboStoreID field starts with ME* (like ME004 or ME100, etc...) and regardless of what txtCharge is set to, always print report1

If cboStoreID field starts with anything else besides ME* (like U182 or W331, etc...) AND txtCharge = 0 then print report2

If cboStoreID field starts with anything else besides ME* (like U182 or W331, etc...) AND txtCharge > 0 then print report3

I was trying IF THEN statements but ran into trying to figure out how to have it check for the ME* vs anything else, as well as wondering if there was a better alternative than 3 different IF THEN statements.

thanks in advance everyone!

Richard
 
Something like this ?
Dim strReport As String, strWhere As String
If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If
If Me.Newrecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Exit Sub
End If
If Me!cboStoreID Like "ME*" Then
strReport = "report1"
ElseIf Me!txtCharge = 0 Then
strReport = "report2"
Else
strReport = "report3"
End If
strWhere = "[ID]=" & Me![ID]
DoCmd.OpenReport strReport, acViewNormal, , strWhere

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Once again, you prove to be the man PHV! Thank you!!

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top