Solved

Access VBA Syntax error Update query between 2 dates

Posted on 2015-02-07
4
444 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 29

Expert Comment

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

Ron
0
 
LVL 50

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 50

Expert Comment

by:Gustav Brock
ID: 40596978
You are welcome!

/gustav
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

759 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