Results 1 to 10 of 10

Thread: where is the syntax error?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    7

    where is the syntax error?

    Could anyone tell me what is wrong with my query syntax?

    code:

    strConditionDates = "(((Mission_Date >= #" & txtDate1 & "#) AND (Mission_Date <= #" & txtDate2 & "#)) AND (Mission_Code = " & Me.ListBoxMission_Code & "))"

    Set rstMissions = CurrentDb.OpenRecordset("select distinct FK_Mission_PK from [sql_équipage des missions] where ((FK_MISSION_PK is not null) AND " & strConditionDates)

    with the debugger strConditionDates takes the following value:

    "(((Mission_Date >= #2005-01-01#) AND (Mission_Date <= #2005-10-05#)) AND (Mission_Code = AI 165 C))"
    Attached Images Attached Images  

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: where is the syntax error?

    The value for Mission_Code needs to be wrapped with single quotes.

    VB Code:
    1. strConditionDates = "(((Mission_Date >= #" & txtDate1 & "#) AND (Mission_Date <= #" & txtDate2 & "#)) AND (Mission_Code = '" & Me.ListBoxMission_Code & "'))"

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    7

    Re: where is the syntax error?

    I changed it but I now get this message
    Attached Images Attached Images  

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: where is the syntax error?

    On the first Mission_Date check (right after the first AND) you have three opening (.

    So, either one of them needs to be removed, or an additional ) needs to be added to the end.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    7

    Re: where is the syntax error?

    this is driving me nuts

    ok...here`s what I came up with and still it is not functionning

    this is what I see in the The watch when I run the debugger:

    "((Mission_Date >= #2005-01-01#) AND (Mission_Date <= #2005-10-05#) AND (Mission_Code = 'AI 165 C'))"

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: where is the syntax error?

    It looks like you still have mismatched brackets. It is not necessary to bracket each field just the expressions you want to evaluate together.

    Assuming I interpreted your intentions correctly, try

    VB Code:
    1. strconditiondates = "( (Mission_Date >= #2005-01-01# AND Mission_Date <= #2005-10-05#)
    2. AND Mission_Code = 'AI 165 C' )"
    3.  
    4. strsql = "select distinct FK_Mission_PK from [sql_équipage des missions]
    5. where FK_MISSION_PK is not null AND " & strconditiondates

    The outcome should be

    VB Code:
    1. select distinct FK_Mission_PK from [sql_équipage des missions]
    2. where FK_MISSION_PK is not null AND ( (Mission_Date >= #2005-01-01# AND Mission_Date <= #2005-10-05#) AND Mission_Code = 'AI 165 C' )

  7. #7
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: where is the syntax error?

    Is this valid syntax? FK_MISSION_PK is not null
    Shouldn't it read: Not FK_MISSION Is Null ?
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: where is the syntax error?

    Is Not Null is valid syntax.

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    7

    Re: where is the syntax error?

    My query was functionning until I added strConditionDates. Therefore I assume that "is not full" works.....

    I have tried all suggestions listed above but no succces.

    Any other suggestions?

    thanks

  10. #10
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Manila, Philippines
    Posts
    486

    Re: where is the syntax error?

    VB Code:
    1. strConditionDates = "[Mission_Date] >= #" & txtDate1 & "# AND [Mission_Date] <= #" & txtDate2 & "# AND [Mission_Code] =‘" & Me.ListBoxMission_Code & "’""
    2.  
    3. Set rstMissions = CurrentDb.OpenRecordset("select distinct FK_Mission_PK from [sql_équipage des missions] where [FK_MISSION_PK] is not null AND " & strConditionDates)

    just a try

Posting Permissions

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



Click Here to Expand Forum to Full Width