1

Ive been trying to get a query I ran in Access to run in VBA but I keep getting errors due to the number of exclamation marks I've been using. The statement I am using is

 SQLstat = "SELECT tbl_Date_Check.DateofChecklist, tbl_Tasks.QuestionNumber,tbl_Tasks.Frequency, tbl_Tasks.Questions " _ 
& "FROM tbl_Tasks, tbl_Date_Check " _
& "WHERE (((tbl_Date_Check.DateofChecklist)=""" & [Forms]![Daily_Checker]![TxtDate] & """) And ((tbl_Tasks.Frequency) = """ & [Forms]![Daily_Checker]![ComFreq]"""))"

Any help would be great thanks

Gablet
  • 21
  • 1
  • 5

2 Answers2

0

This can possibly be explained by the following SO question: What is the difference between single and double quotes in SQL?

This explains that you need to utilize single quotes '' to surround text in SQL in almost every instance. The fact that you are using double quotes "" may be what is causing the error.

I hope this helps.

-C§

Community
  • 1
  • 1
CSS
  • 412
  • 5
  • 17
  • 1
    The question you reference does not apply to Microsoft Access SQL. The answer in that question refers more to Microsoft SQL Server (TSQL). For Microsoft Access, either single quotes or double quotes can be used to delimit strings without any problems. His error is that he is missing a concatenation symbol at the end of the statement, as pointed out by @HansUp in his comment on the OP. He may also have the need to use the `#` date delimiter as pointed out by @Gustav if he is indeed comparing two date fields (`DateofChecklist` and `TxtDate`), but that is not known for sure based on the post. – Jericho Johnson Sep 25 '15 at 15:59
0

It must read like this for dates:

SQLstat = "SELECT tbl_Date_Check.DateofChecklist, tbl_Tasks.QuestionNumber,tbl_Tasks.Frequency, tbl_Tasks.Questions " _ 
& "FROM tbl_Tasks, tbl_Date_Check " _
& "WHERE ((tbl_Date_Check.DateofChecklist = #" & Format([Forms]![Daily_Checker]![TxtDate], "yyyy\/mm\/dd") & "#) And (tbl_Tasks.Frequency = " & [Forms]![Daily_Checker]![ComFreq] & "))"
Gustav
  • 53,498
  • 7
  • 29
  • 55