Sql String being truncated (1 Viewer)

raziel3

Registered User.
Local time
Yesterday, 20:10
Joined
Oct 5, 2017
Messages
276
Hi all,
This is the statement I'm trying to pass through VBA

Code:
BioClockSql = "SELECT EmpTimes.USERID " & _
                ",EmpTimes.EID " & _
                ",EmpTimes.CHECKDATE " & _
                ",Format([CHECKDATE],'ddd') AS DOW " & _
                ",EmpTimes.INTIME " & _
                ",EmpTimes.OUTTIME " & _
                ",EmpTimes.TIMEWORKED " & _
                ",EmpTimes.TIMEDURATION " & _
                ",TimeSheet.WDate " & _
                "FROM EmpTimes " & _
         "LEFT JOIN TimeSheet ON (EmpTimes.CHECKDATE = TimeSheet.WDate) " & _
         "AND (EmpTimes.EID = TimeSheet.EID) " & _
         "WHERE (((EmpTimes.CHECKDATE) Between [Forms]![frmPay1]![txtPSTART] " & _
         "AND [Forms]![frmPay1]![txtPEND]) " & _
         "AND ((TimeSheet.WDate) Is Null))"""

In the locals window it is being trimmed off at
Code:
"LEFT JOIN TimeSheet ON (EmpTimes.CHECKDATE = TimeSheet.WDate) " & _

truncated.jpg

What am I doing wrong?
 

cheekybuddha

AWF VIP
Local time
Today, 01:10
Joined
Jul 21, 2014
Messages
2,321
When you are at that breakpoint, what happens if you type in the Immediate Window:
?BioClockSql
and hit enter?
 

raziel3

Registered User.
Local time
Yesterday, 20:10
Joined
Oct 5, 2017
Messages
276
Code:
SELECT EmpTimes.USERID ,EmpTimes.EID ,EmpTimes.CHECKDATE ,Format([CHECKDATE],'ddd') AS DOW ,EmpTimes.INTIME ,EmpTimes.OUTTIME ,EmpTimes.TIMEWORKED ,EmpTimes.TIMEDURATION ,TimeSheet.WDate FROM EmpTimes LEFT JOIN TimeSheet ON (EmpTimes.CHECKDATE = TimeSheet.WDate) AND (EmpTimes.EID = TimeSheet.EID) WHERE (((EmpTimes.CHECKDATE) Between [Forms]![frmPay1]![txtPSTART] AND [Forms]![frmPay1]![txtPEND]) AND ((TimeSheet.WDate) Is Null))"

I'm getting the full statement but runtime error 3075
truncated 2.jpg
 

raziel3

Registered User.
Local time
Yesterday, 20:10
Joined
Oct 5, 2017
Messages
276
The query runs fine using the GUI
truncated 3.jpg

but if I reference it like this
Set BioClockRS = db.OpenRecordset("qryBioClock", dbOpenSnapshot)

truncated 4.jpg

Error 3061
 

cheekybuddha

AWF VIP
Local time
Today, 01:10
Joined
Jul 21, 2014
Messages
2,321
Why do you need the extra double quotes at the end?

Anyway, you need to concatenate the form references when using VBA:
Code:
BioClockSql = "SELECT EmpTimes.USERID " & _
                ",EmpTimes.EID " & _
                ",EmpTimes.CHECKDATE " & _
                ",Format([CHECKDATE],'ddd') AS DOW " & _
                ",EmpTimes.INTIME " & _
                ",EmpTimes.OUTTIME " & _
                ",EmpTimes.TIMEWORKED " & _
                ",EmpTimes.TIMEDURATION " & _
                ",TimeSheet.WDate " & _
                "FROM EmpTimes " & _
         "LEFT JOIN TimeSheet ON (EmpTimes.CHECKDATE = TimeSheet.WDate) " & _
         "AND (EmpTimes.EID = TimeSheet.EID) " & _
         "WHERE (((EmpTimes.CHECKDATE) Between " & Format([Forms]![frmPay1]![txtPSTART], "\#yyyy\-mm\-dd hh:nn:ss\#") & " " & _
         "AND " & Format([Forms]![frmPay1]![txtPEND], "\#yyyy\-mm\-dd hh:nn:ss\#") & " " & _
         "AND ((TimeSheet.WDate) Is Null))"
 
Last edited:

raziel3

Registered User.
Local time
Yesterday, 20:10
Joined
Oct 5, 2017
Messages
276
Yeah, used a different online sql to vba converter. The extra quotes and brackets were the problem.

Thanks

Code:
"WHERE (((EmpTimes.CHECKDATE) Between #4/23/2023# AND #4/29/2023#) " & _
         "AND ((TimeSheet.WDate) Is Null))"
 

cheekybuddha

AWF VIP
Local time
Today, 01:10
Joined
Jul 21, 2014
Messages
2,321
Yeah, sorry, missed the brackets 😬

You can actually remove all of them from your WHERE clause!
Code:
' ...
         "WHERE EmpTimes.CHECKDATE Between " & Format([Forms]![frmPay1]![txtPSTART], "\#yyyy\-mm\-dd hh:nn:ss\#") & " " & _
         "AND " & Format([Forms]![frmPay1]![txtPEND], "\#yyyy\-mm\-dd hh:nn:ss\#") & " " & _
         "AND TimeSheet.WDate Is Null"
 

Users who are viewing this thread

Top Bottom