Command Button prints 2 reports

  • Thread starter Thread starter dottie09
  • Start date Start date
D

dottie09

I have created a command button that prints 2 reports. I want to add a 3rd
report to print but only if it meets criteria.

For instance, if leave is for a serious health condition then print medical
clearance form. Field "Serious Health Condition" yes/no field, Report =
Medical Clearance Form.

Any suggestions would be appreciated.
 
I have created a command button that prints 2 reports. I want to add a 3rd
report to print but only if it meets criteria.

For instance, if leave is for a serious health condition then print medical
clearance form. Field "Serious Health Condition" yes/no field, Report =
Medical Clearance Form.

Any suggestions would be appreciated.

DoCmd.OpenReport "Report1"
DoCmd.OpenReport "Report2"
If Me.[SeriousHealthCondition] = -1 Then
DoCmd.OpenReport "MedicalClearanceForm"
End If
 
Thank you for the response.

I'm still having trouble. I want it to print the reports based off of the
current record. I guess I should have included that tidbit. It's giving me
a compile error. "Block if without End if"

Here is the code I am using:

Private Sub Cmdprint_Enter()
Dim 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"
Else
strWhere = "[Employee #]=" & Me.[Employee #]
DoCmd.OpenReport "FMLA Leave Request", acViewPreview, , strWhere
DoCmd.OpenReport "Pt 1-leave request", acViewPreview, , strWhere
If Me.[Serious Health Condition] = -1 Then
DoCmd.OpenReport "Medical Clearance Form", acViewPreview, , strWhere
End If
End Sub

fredg said:
I have created a command button that prints 2 reports. I want to add a 3rd
report to print but only if it meets criteria.

For instance, if leave is for a serious health condition then print medical
clearance form. Field "Serious Health Condition" yes/no field, Report =
Medical Clearance Form.

Any suggestions would be appreciated.

DoCmd.OpenReport "Report1"
DoCmd.OpenReport "Report2"
If Me.[SeriousHealthCondition] = -1 Then
DoCmd.OpenReport "MedicalClearanceForm"
End If
 
Thank you for the response.

I'm still having trouble. I want it to print the reports based off of the
current record. I guess I should have included that tidbit. It's giving me
a compile error. "Block if without End if"

Here is the code I am using:

Private Sub Cmdprint_Enter()
Dim 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"
Else
strWhere = "[Employee #]=" & Me.[Employee #]
DoCmd.OpenReport "FMLA Leave Request", acViewPreview, , strWhere
DoCmd.OpenReport "Pt 1-leave request", acViewPreview, , strWhere
If Me.[Serious Health Condition] = -1 Then
DoCmd.OpenReport "Medical Clearance Form", acViewPreview, , strWhere
End If
End Sub
*** snipped ***
Do you want it to print the reports or preview the reports?
You are having it preview, so I'll do that also.
You had an If Then Else in your code, then you added my If Then Else
code without adding a closing End If. If you get into the habit of
indenting your code (as I have done below) within the If .. End If's
you will find it easier to debug if you get a Block If without End If
error.

Try it like this to preview all the reports:

Private Sub Cmdprint_Enter()
Dim 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"
Else
strWhere = "[Employee #]=" & Me.[Employee #]
DoCmd.OpenReport "FMLA Leave Request", acViewPreview, , strWhere
DoCmd.OpenReport "Pt 1-leave request", acViewPreview, , strWhere
If Me.[Serious Health Condition] = -1 Then
DoCmd.OpenReport "Medical Clearance Form", acViewPreview, ,
strWhere
End If
End If
End Sub
 
Thank you! Worked like a charm. I appreciate your help!

fredg said:
Thank you for the response.

I'm still having trouble. I want it to print the reports based off of the
current record. I guess I should have included that tidbit. It's giving me
a compile error. "Block if without End if"

Here is the code I am using:

Private Sub Cmdprint_Enter()
Dim 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"
Else
strWhere = "[Employee #]=" & Me.[Employee #]
DoCmd.OpenReport "FMLA Leave Request", acViewPreview, , strWhere
DoCmd.OpenReport "Pt 1-leave request", acViewPreview, , strWhere
If Me.[Serious Health Condition] = -1 Then
DoCmd.OpenReport "Medical Clearance Form", acViewPreview, , strWhere
End If
End Sub
*** snipped ***
Do you want it to print the reports or preview the reports?
You are having it preview, so I'll do that also.
You had an If Then Else in your code, then you added my If Then Else
code without adding a closing End If. If you get into the habit of
indenting your code (as I have done below) within the If .. End If's
you will find it easier to debug if you get a Block If without End If
error.

Try it like this to preview all the reports:

Private Sub Cmdprint_Enter()
Dim 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"
Else
strWhere = "[Employee #]=" & Me.[Employee #]
DoCmd.OpenReport "FMLA Leave Request", acViewPreview, , strWhere
DoCmd.OpenReport "Pt 1-leave request", acViewPreview, , strWhere
If Me.[Serious Health Condition] = -1 Then
DoCmd.OpenReport "Medical Clearance Form", acViewPreview, ,
strWhere
End If
End If
End Sub
 
Back
Top