From: Micki on
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?

From: Marshall Barton on
Micki wrote:
>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

--
Marsh
MVP [MS Access]
From: Micki on
Thanks Marshall! That did the trick.

"Marshall Barton" wrote:

> Micki wrote:
> >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
>
> --
> Marsh
> MVP [MS Access]
> .
>