Report based on field criteria

M

Micki

I have a form (frmJobs) with a field called ClientName. If ClientName is
similar to certain criteria, I need one report to display. If ClientName is
not similar to the criteria, a different report should display. This is the
code I currently have:

Private Sub PrelimRpt_Click()

If Me.ClientName = "Apache*" Then
DoCmd.OpenReport "DISAJobReport ", acViewPreview

If Me.ClientName = "El Paso*" Then
DoCmd.OpenReport "DISAJobReport", acViewPreview
End If

Else: DoCmd.OpenReport "JobReport", acViewPreview
End If

End Sub

Unfortuately, the Else option (JobReport) displays regardless of the field
contents. Can anyone help?
 
M

Marshall Barton

Micki said:
I have a form (frmJobs) with a field called ClientName. If ClientName is
similar to certain criteria, I need one report to display. If ClientName is
not similar to the criteria, a different report should display. This is the
code I currently have:

Private Sub PrelimRpt_Click()

If Me.ClientName = "Apache*" Then
DoCmd.OpenReport "DISAJobReport ", acViewPreview

If Me.ClientName = "El Paso*" Then
DoCmd.OpenReport "DISAJobReport", acViewPreview
End If

Else: DoCmd.OpenReport "JobReport", acViewPreview
End If

End Sub

Unfortuately, the Else option (JobReport) displays regardless of the field
contents. Can anyone help?


The correct way to do that logic would be:

If Me.ClientName Like "Apache*" Then
DoCmd.OpenReport "DISAJobReport", acViewPreview
ElseIf Me.ClientName Like "El Paso*" Then
DoCmd.OpenReport "DISAJobReport", acViewPreview
Else
DoCmd.OpenReport "JobReport", acViewPreview
End If

Or. a little more concisely:

If Me.ClientName Like "Apache*" _
OR Me.ClientName Like "El Paso*" Then
DoCmd.OpenReport "DISAJobReport", acViewPreview
Else
DoCmd.OpenReport "JobReport", acViewPreview
End If
 
M

Micki

Thanks Marshall! That did the trick.

Marshall Barton said:
The correct way to do that logic would be:

If Me.ClientName Like "Apache*" Then
DoCmd.OpenReport "DISAJobReport", acViewPreview
ElseIf Me.ClientName Like "El Paso*" Then
DoCmd.OpenReport "DISAJobReport", acViewPreview
Else
DoCmd.OpenReport "JobReport", acViewPreview
End If

Or. a little more concisely:

If Me.ClientName Like "Apache*" _
OR Me.ClientName Like "El Paso*" Then
DoCmd.OpenReport "DISAJobReport", acViewPreview
Else
DoCmd.OpenReport "JobReport", acViewPreview
End If
 

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