If Then Conditional Help

  • Thread starter Thread starter Jackie24
  • Start date Start date
J

Jackie24

I am fairly new at working with code.
I am trying to write a statement that will open one report if a feild is true,
and another if it is False. This is what I have so far

Dim stDocName As String
Dim strCriteria As String

strCriteria = "[Event Name]='" & Me![Event Name] & "'"
If ([Cash Calculations].[NewEvent] = Yes) Then
DoCmd.OpenReport NewEvntCashCalc, acViewPreview, , strCriteria
Else
DoCmd.OpenReport PrevEvntCashCalcu, acPreview, , stCriteria

End If

When I try to run this code I get the Error Message
"Microsoft Access Can't Find Field "|" Referred to in your Expression"

Can anyone help me with this problem
 
The first problemis that the name of a form must be either in qoutes or in a
variable in the OpenForm method.

As to your error, you don't say on which line it occurs; however, I suspect
it is looking for the field [Event Name] and can't find it.

Here is how I would code it:

strCriteria = "[Event Name]='" & Me![Event Name] & "'"
If [Cash Calculations].[NewEvent] = True Then
stDocName = "NewEvntCashCalc"
Else
stDocName = "PrevEvntCashCalc"
End If
DoCmd.OpenReport strDocName, acViewPreview, , strCriteria
 
Back
Top