0

Can anyone spot the syntax error? I feel like I have all the operators for the OpenRecordset method that are necessary.

The error says "Syntax error (missing operator) in query expression '(Date: = 10/31/2014)'.

the class variable is equal to the string "007-14 A"

Below is the line of code where the error is coming from:

Set rec = db.OpenRecordset("SELECT '" & class & "' FROM tblCalendar WHERE (Date: = 10/31/2014)")

Do I have the wrong quotes around the wrong things or could it have to do with the semicolon in the title of the field Date?

class is a field I want to select. So the actual field title is 007-14 A.

3
  • 3
    the : is probably not needed after the Date Commented Sep 3, 2014 at 13:00
  • 1
    I thought Access used [] to define fields not '. Commented Sep 3, 2014 at 13:11
  • @xQbert That did the trick!!! Thanks man I also had the mistakes explained below though so perfect! Commented Sep 3, 2014 at 13:21

1 Answer 1

7

You have 3 errors here. '007-14 A' and Date: are not legal column names, and 10/31/2014 is not a legal date literal value.

Wrap illegal column names in square brackets, e.g. [007-14 A] and [Date:]

Format the date literal value as #10/31/2014#

If that date literal format does not work, try #31 Oct 2014#

NOTE: MS Access uses the JET engine SQL dialect, which looks suspiciously similar to VB (I guess it's leveraging the VBA engine for parsing under the hood). Generally speaking, you can use the same literal syntax and built-in functions across VB6, VBA, VBScript, ADO disconnected recordset filters, and MS Access queries. However, there are subtle differences which can trip you up.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.