Link to home
Start Free TrialLog in
Avatar of Floyd Sumner
Floyd Sumner

asked on

Using dynamic variables in an Access 2010 SQL Query

What is the proper syntax for dynamic variables inside a MS Access 2010 SQL Select query?

Following is the code I'm trying to complete and I can't recall the correct syntax for placing dynamic variables inside a MS Access 2010 SQL Select query;

Dim STDate, EnDate As Date
Dim STtime, EnTime As Variant
Dim ProArea,  SQLSearch As String

ProArea = Me.ProgArea
STDate = Me.StartDT
STime = Me.cmb_StartTime
EnDate = Me.EndDT
EnTime = Me.cmb_EndTime

SQLSearch = "SELECT VehiclePool.[Unit#], VehiclePool.[Year, Make, Model], VehiclePool.Program, VehiclePool.Location, tbl_VehicleSchedule.PurposeOfTrip, " & _
"tbl_VehicleSchedule.StartDT, tbl_VehicleSchedule.EndDT INTO tbl_VehicleDatesResults " & _

"FROM VehiclePool INNER JOIN tbl_VehicleSchedule ON VehiclePool.[Unit#] = tbl_VehicleSchedule.[Unit#] " & _

"WHERE (((VehiclePool.[Unit#]) Is Not Null) AND ((VehiclePool.Program)= ProArea) AND ((tbl_VehicleSchedule.StartDT)=IsNull((([tbl_VehicleSchedule].[StartDT]) " & _
"Between STDate And EnDate) Or ([tbl_VehicleSchedule].[StartDT])=IsEmpty(([tbl_VehicleSchedule].[StartDT]) Between STDate And EnDate)) Or " & _
"(tbl_VehicleSchedule.StartDT) Is Null) AND ((tbl_VehicleSchedule.EndDT)=IsNull((([tbl_VehicleSchedule].[EndDT]) Between STDate And EnDate) Or " & _
"([tbl_VehicleSchedule].[EndDT])=IsEmpty(([tbl_VehicleSchedule].[EndDT]) Between STDate And EnDate)) Or (tbl_VehicleSchedule.EndDT) Is Null));"
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Floyd Sumner
Floyd Sumner

ASKER

Thanks to both of you.
@ste5an,

<<Dim STDate, EnDate As Date>>

 Good catch!

Jim.