Link to home
Start Free TrialLog in
Avatar of ExpressMan1
ExpressMan1Flag for Canada

asked on

Access VBA Syntax error Update query between 2 dates

Getting a Syntax error. I am trying to update a field based on the date on a form.  Forms!frmRateTool!CurrentDate  or Me.CurrentDate (Not sure which one to use).  Not sure how to write the "Between line.

Dim db As DAO.Database
 Dim qdfFuel As DAO.QueryDef
 Dim strSQLFuel As String
 Dim strDb As String
 
 strDb = "C:\Users\Austin\Documents\Access Development\RateTool.accdb"
 
  strSQLFuel = "UPDATE (tblFedExServices INNER JOIN tblFuel " & _
    "ON tblFedExServices.FuelServiceID = tblFuel.FuelServiceID) INNER JOIN tblRate " & _
    "ON (tblFuel.OriginCountryID = tblRate.OriginCountryID) " & _
    "AND (tblFedExServices.ServiceID = tblRate.ServiceID) SET tblRate.FuelPercentage = tblFuel.[FuelPercentage] " & _
    "WHERE " & Chr(34) & Me.CurrentDate & Chr(34) & _
    "Between # & [tblFuel].[StartDate] & # And # & [tblFuel].[EndDate] & #;"
       
    Set db = OpenDatabase(strDb)
   
    Set qdfFuel = db.CreateQueryDef("", strSQLFuel)
    qdfFuel.Execute
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Change this line:
"Between [tblFuel].[StartDate] And [tblFuel].[EndDate];"

Ron
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark 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
Avatar of ExpressMan1

ASKER

Perfect! Thank You Gustav
You are welcome!

/gustav