PDA

View Full Version : [SOLVED:] VBA, Error 3075



Anehab
05-02-2016, 04:53 AM
1607016069
16071

I keep getting this error. I try to add " to the end of my WHERE statement. I recently changed it from


strSQL = "SELECT Clients.Unit, COUNT(Events.Client_ID) as TimesTasked " _
& "FROM Clients LEFT JOIN Events ON Clients.Client_ID = Events.Client_ID " _
& "WHERE Events.Event_Start_DateTime <= #" & txtEndDate & "# AND Events.Event_End_DateTime >= #" & txtStartDate & "# AND Clients.Unit = """ & Unit & """ _
& " GROUP BY Clients.Unit;"

Once I run the code VB changes the three " after Unit to four """". So I changed it to the statement below.


strSQL = "SELECT Clients.Unit, COUNT(Events.Client_ID) as TimesTasked " _
& "FROM Clients LEFT JOIN Events ON Clients.Client_ID = Events.Client_ID " _
& "WHERE Events.Event_Start_DateTime <= #" & txtEndDate & "# AND Events.Event_End_DateTime >= #" & txtStartDate & "# AND Clients.Unit LIKE *" & Unit & "*" _
& " GROUP BY Clients.Unit;"

Honestly I wish I knew more about SQL but right now I am still learning and I really need the assistance. Im happy to provide any information that would be helpful to reaching a solution.

SamT
05-02-2016, 02:27 PM
Try

Const QM As String = """
. . .
. . . Clients.Unit = " & QM & Unit & QM _
& " GROUP BY Clients.Unit;"

It can get confusing when assigning quote marks inside a concatenated string, substituting a Variable for a quoted quote mark eliminates that issue

Anehab
05-04-2016, 07:04 AM
Thank you! works great!