Command Button prints 2 reports

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.
 
F

fredg

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
 
D

dottie09

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
 
F

fredg

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
 
D

dottie09

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
 

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