If Then Conditional Help

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
 
K

Klatuu

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
 

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