From: Micki on 13 Feb 2010 12:10 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 13 Feb 2010 12:49 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 13 Feb 2010 16:40 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] > . >
|
Pages: 1 Prev: looking for a way to unlock a back end mdb file Next: Combo Box problem |