Report based on field criteria

  • Thread starter Thread starter Micki
  • Start date Start date
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?
 
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
 
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
 
Back
Top