Solved

Access VBA Syntax error Update query between 2 dates

Posted on 2015-02-07
4
437 Views
Last Modified: 2016-02-10
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
0
Comment
Question by:ExpressMan1
  • 2
4 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 40596511
Change this line:
"Between [tblFuel].[StartDate] And [tblFuel].[EndDate];"

Ron
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40596585
This is how:

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 #" & Format(Me!CurrentDate, "yyyy\/mm\/dd") & "# " & _
     "Between [tblFuel].[StartDate] And [tblFuel].[EndDate];"

/gustav
0
 

Author Closing Comment

by:ExpressMan1
ID: 40596972
Perfect! Thank You Gustav
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40596978
You are welcome!

/gustav
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question