Share via

Where's the missing operator?

Anonymous
2011-02-11T03:28:18+00:00

I created a button on a form which opens another form where the AdjudicatorKey and Date fields in the second form equals the same fields in the first form.

In the On Click event I have the following code (along with the Dim, etc. lines)

    stDocName = "frmMiniSchedule"

    DoCmd.OpenForm stDocName, , , "[AdjudicatorKey] = " & Me.AdjudicatorKey & " AND [Date] = " & Me.Date & ""

when I click the button I get this error message:

Syntax error (missing operator) in query expression ‘[AdjudicatorKey] = 13 AND [Date] = Saturday November 13’.

Where's the missing operator?

Thanks in advance.

Jerry

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-02-11T04:16:24+00:00

"JWCrosby" wrote in message

news:*** Email address is removed for privacy ***...

> Thanks, Dirk. I created this database in an earlier life when I didn't

> know better than to use the field name "Date."  So I made some changes and

> in the queries for the two forms changed the name of the Date field to

> AssignedDate. Actually, that field is a string (ex, "Saturday November

> 20") and not really a date.

>

> So, now I have this code, but still get the same error:

>

>    DoCmd.OpenForm stDocName, , , "[AdjudicatorKey] = " & Me.AdjudicatorKey

> & " AND [AssignedDate] = " & Me.AssignedDate

>

> Appreciate any further help.

>

> Jerry

>

If it's not really a date, you won't use the # character to delimit the

value, but since what it really is is a text value, you need to put it in

quotes.  Assuming it won't ever contain the single-quote character ('), you

can use that as the quote for the text value, which makes life a bit easier:

'

DoCmd.OpenForm stDocName, , , _

"[AdjudicatorKey] = " & Me.AdjudicatorKey & _

" AND [AssignedDate] = '" & Me.AssignedDate & "'"


Dirk Goldgar, MS Access MVP

Access tips: www.datagnostics.com/tips.html

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-02-11T04:19:26+00:00

    Blessings on you, Dirk, that did it!

    Thanks!

    Jerry

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-02-11T03:54:49+00:00

    Thanks, Dirk. I created this database in an earlier life when I didn't know better than to use the field name "Date."  So I made some changes and in the queries for the two forms changed the name of the Date field to AssignedDate. Actually, that field is a string (ex, "Saturday November 20") and not really a date.

    So, now I have this code, but still get the same error:

        DoCmd.OpenForm stDocName, , , "[AdjudicatorKey] = " & Me.AdjudicatorKey & " AND [AssignedDate] = " & Me.AssignedDate

    Appreciate any further help.

    Jerry

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-02-11T03:43:45+00:00

    "JWCrosby" wrote in message

    news:*** Email address is removed for privacy ***...

    >I created a button on a form which opens another form where the

    >AdjudicatorKey and Date fields in the second form equals the same fields in

    >the first form.

    >

    > In the On Click event I have the following code (along with the Dim, etc.

    > lines)

    >

    >

    >    stDocName = "frmMiniSchedule"

    >

    >    DoCmd.OpenForm stDocName, , , "[AdjudicatorKey] = " & Me.AdjudicatorKey

    > & " AND [Date] = " & Me.Date & ""

    >

    > when I click the button I get this error message:

    >

    > Syntax error (missing operator) in query expression ‘[AdjudicatorKey] = 13

    > AND [Date] = Saturday November 13’.

    >

    > Where's the missing operator?

    >

    You need to enclose the date you want in the date-delimiters (#), and you

    have to format it in such a way that it can be interpreted correctly.  The

    standard for Access queries is MM/DD/YYYY format, although any unambiguous

    format will do.  In your example above, your date is being placed into the

    criteria string without any year.  I'm not sure without testing whether that

    will be interpreted correctly or not.  I recommend this:

    '

    DoCmd.OpenForm stDocName, , , _

    "[AdjudicatorKey] = " & Me.AdjudicatorKey & _

    " AND [Date] = #" & Format(Me.Date, "mm/dd/yyyy") & "#"

    '

    By the way "Date" is a terrible name for a field, as it can easily be

    misinterpreted as the built-in function, "Date".


    Dirk Goldgar, MS Access MVP

    Access tips: www.datagnostics.com/tips.html

    Was this answer helpful?

    0 comments No comments