What does error message mean?

T

Tony Williams

I have this line of code which should open a form
DoCmd.OpenForm (TimeCards2, , , "[ProjectID] = '" &
Forms!Clients!Clientssubform.Form!ProjectID & "'")

However I get an error message that says " Expected = "

I have an = in my code, can anyone help?
Thanks
Tony
 
A

Allen Browne

If TimeCards2 is the name of the form, it needs to be in quotes:
DoCmd.OpenForm "TimeCards2", , , ...

The brackets are not needed.

If that's still not right, what is the data type of ProjectID?
If Number, omit the quotes. (They are used for Text fields, not Number
fields.)

You might end up with something like this:
Dim strWhere As String
If Not IsNull(Forms!Clients!Clientssubform.Form!ProjectID) Then
strWhere = "[ProjectID] = " &
Forms!Clients!Clientssubform.Form!ProjectID
End If
DoCmd.OpenForm "TimeCards2", WhereCondition:=strWhere
 
S

Stefan Hoffmann

hi Tony,

Tony said:
I have this line of code which should open a form
DoCmd.OpenForm (TimeCards2, , , "[ProjectID] = '" &
Forms!Clients!Clientssubform.Form!ProjectID & "'")

However I get an error message that says " Expected = "

I have an = in my code, can anyone help?
You have a syntax error in the way you are calling the method. You can use:

Call Method(Parameters)

Method Parameters

ReturnValue = Method(Parameters)

The brackets around your parameter list are not necessary.


mfG
--> stefan <--
 
V

Van T. Dinh

Don't use the parentheses around the arguments. Also, if "TimeCards2" is the
name of the Form, you need to enclose it in the String delimiters like:

DoCmd.OpenForm "TimeCards2", , , "[ProjectID] = '" & _
Forms!Clients!Clientssubform.Form!ProjectID & "'"

assuming that [ProjectID] is of Text type from your statement.

If you want to use parentheses, you need to use the Call statement like:

Call DoCmd.OpenForm("TimeCards2", , , "[ProjectID] = '" & _
Forms!Clients!Clientssubform.Form!ProjectID & "'")
 
S

Stefan Hoffmann

hi,
Don't use the parentheses around the arguments.
This was my first thought, but

DoCmd.OpenForm ("Form")

is equivalent to

DoCmd.OpenForm "Form"

as far as i've tested earlier. It doesn't cause the "expect =" error.


mfG
--> stefan <--
 
D

Douglas J. Steele

Stefan Hoffmann said:
hi,

This was my first thought, but

DoCmd.OpenForm ("Form")

is equivalent to

DoCmd.OpenForm "Form"

as far as i've tested earlier. It doesn't cause the "expect =" error.

You're correct that with a single parameter, putting parentheses is okay.
Once you've got more than 1 parameter, though, you cannot use parentheses
around them.

The original poster could have got away with:

DoCmd.OpenForm (TimeCards2), , , ("[ProjectID] = '" &
Forms!Clients!Clientssubform.Form!ProjectID & "'")

as well, but realistically, the rule is no parenthesis unless you're using
the method as a function (which you can't do with DoCmd.OpenForm)
 
V

Van T. Dinh

Sorry, I didn't test the single argument case.

I tested with the arguments similar to the O.P. posted and found that the
Call worked with what the O.P. posted. I never used it this way in my
codes, though.
 
Top