Results 1 to 4 of 4
  1. #1
    FrustratedAlso is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Apr 2012
    Posts
    35

    Syntax error on VB Select Where Clause


    Code:
    SalStrSql = "Select Sales.[VendorID], Sales.[vInvoiceNumber], Sales.[Consigned], Sales.[Quantity], Sales.[TagPrice], Sales.[DiscountPercent], Sales.[SaleDate] from Sales WHERE (Sales.[VendorID] = """ & dNbr & """ AND Sales.[vInvoiceNumber] Is Null AND (Sales.[SaleDate] >= # " & Format(PeriodStart, "M/D/YYYY") & "# And Sales.[SaleDate] <= #" & Format(PeriodEnd, "M/D/YYYY") & "#))"""
    Gives syntax error on this portion

    Code:
    (Sales.[VendorID] = """ & dNbr & """ AND Sales.[vInvoiceNumber] Is Null AND (Sales.[SaleDate] >= # " & Format(PeriodStart, "M/D/YYYY") & "# And Sales.[SaleDate] <= #" & Format(PeriodEnd, "M/D/YYYY") & "#))"""
    Help! I've stared at it so much I'm going blind

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    My recommendation is to build an example of this query in Query Builder, and make sure you get it working properly. Then switch to SQL View and Copy and Paste the SQL code out to a text file.

    Then, where you have built the SQL code construction in VBA, return the code to a Message Box before running it. Then compare those results to the copy of the SQL code you have in your Text file, and locate the differences. Basically, your goal is to modify your VBA code so that what is returned in your Message Box matches the working code in your Text file. Once you do accomplish that, your code should run without errors.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The last triple quote should be a single.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    FrustratedAlso is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    35
    Thanks, I took a nap and figured it out

Please reply to this thread with any new information or opinions.

Similar Threads

  1. syntax error in from clause
    By jskamm in forum Access
    Replies: 2
    Last Post: 09-18-2012, 09:13 AM
  2. Syntax Error in FROM clause
    By cjohnston in forum Queries
    Replies: 2
    Last Post: 02-15-2012, 07:33 AM
  3. Syntax error on WHERE clause, possible type conflict?
    By shubhamgandhi in forum Programming
    Replies: 3
    Last Post: 07-21-2011, 01:23 PM
  4. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM
  5. Where clause syntax
    By stupesek in forum Reports
    Replies: 7
    Last Post: 09-03-2010, 02:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums