+ Reply to Thread
Results 1 to 4 of 4

Queries in VBA

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Queries in VBA

    I have another problem with generating queries in code
    I get a SQL syntax error which I have narrowed down to the last addition to the SQL string (marked with*)
    Please Login or Register  to view this content.
    I get confused with the quote marks and i expect theses are wrong, but I have not been able to see how.
    Can anyone help please
    John
    Last edited by j_Southern; 03-26-2012 at 10:24 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Queries in VBA

    Quotes were ok - use Chr(34) instead of "" if you find the latter difficult to read. MsgBox strSQL also helps to see the string generated.

    The problem was mismatching parentheses. Try the last 2 lines as:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Queries in VBA

    Hi Chippy,
    It seems that the mismatched parenthases were not the only problem.
    There does still seem to be something wrong with the date criterion line.
    This code works
    Please Login or Register  to view this content.
    The parenthases in the remed out lines are not the same as yours because I had tried several versions before looking at the last criterion line again.
    With reference to the parantheses, do I actualy need them? None of the criteria are nested, they are all of the same level of"importance"
    The brackets are only there because I originaly copied the lines from the SQL statement in MSQuery.
    John

  4. #4
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Manchester England
    MS-Off Ver
    Excel 2010
    Posts
    992

    Re: Queries in VBA

    Chippy (and others)
    Please don't waste any more time on this problem.
    There was nothing wrong with the date criterion except that StartD was empty due to an earlier typo.
    All is working now.
    Thanks very much for your help on the paranthases though, they definitely did need sorting.
    John

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1