Results 1 to 9 of 9
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Query Problem (MSACESS 2003)

    i have a query that fails to give an output if I clear the remmed out line, although it asks for a keyword first.
    Any suggestions, thanks


    MYSQL = "SELECT TXCLIPS.Shot, KEYWORDS.Keyword,TXCLIPS.Comments, TXCLIPS.NNAME "
    MYSQL = MYSQL & "FROM (TXMASTERS INNER JOIN TXCLIPS ON TXMASTERS.ID1=TXCLIPS.ID1) "
    MYSQL = MYSQL & "INNER JOIN (AthleteNames INNER JOIN JUNCTION ON AthleteNames.AthleteID = JUNCTION.AthleteID) "
    MYSQL = MYSQL & "ON TXCLIPS.ID2 = JUNCTION.ID2 "

    ' '''''MYSQL = MYSQL & "INNER JOIN KEYWORDS ON TXCLIPS.Comments Like '*' & KEYWORDS.Keyword & ' *' "

    MYSQL = MYSQL & "WHERE (((AthleteNames.Athlete) Like [Forms]![TESTQUERIESOUT].[Form].[LA].[Caption])) "
    Me.List1.RowSource = MYSQL

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Query Problem (MSACESS 2003)

    You probably need to apply parentheses to the various join statements in a consistent way. I'd create the query interactively until it works correctly, then transfer the SQL to VBA.

  4. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Query Problem (MSACESS 2003)

    I have a standard way of solving problems like this.

    Add debug.print mysql
    at a point after you have finished compiling the sql.
    Run the code, then look in the immediate window at the sql generated.

    Sometimes I can see what is wrong, but usually I need to copy it, then create a new query, switch to sql view and paste it in.

    Try to switch to design view or datasheet view, and Access will help you find the error. Fix the Sql, then go back and fix the code.

    What do you mean by "Clear" ? Remove the whole line (which should not make any difference) or just remove the apostrophe so it is no longer remmed?
    Regards
    John



  5. #4
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query Problem (MSACESS 2003)

    Thanks Hans. I have tried doing things in the query grid, however the table of Keywords is not linked in anyway, so if I put the field comments into the grid, and keyword into another column, I cannot see how I can create a stement to link them in any way.

    The original rowsource for the list relied on matching a name which was one of the fields. However names are all now in a junction table. The original VB that worked was:

    Me.L14.RowSource = "SELECT TXCLIPS.Shot, KEYWORDS.Keyword,TXCLIPS.Comments, TXCLIPS.NNAME" _
    & " FROM (TXMASTERS INNER JOIN TXCLIPS ON TXMASTERS.ID1=TXCLIPS.ID1)" _
    & " INNER JOIN KEYWORDS ON TXCLIPS.Comments Like '*' & KEYWORDS.Keyword & ' *' " _
    & "WHERE Trim(TXCLIPS.NName) Like '*" & Replace(Me!LNAME4.Caption, "'", "''") & "*' " _
    & "AND (((TXMASTERS.SportorSports) Like [FORMS]![ShotsKeywords].[LNAME5].[CAPTION]))" _
    & " AND Not (TXCLIPS.Shot Is Null)" _
    & "ORDER BY 1"

    Don;t know if that turns any lights on? Regards

  6. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Query Problem (MSACESS 2003)

    I obviously can't test the following, perhaps it'll do what you want
    <code>
    MYSQL = "SELECT TXCLIPS.Shot, KEYWORDS.Keyword,TXCLIPS.Comments, TXCLIPS.NNAME "
    MYSQL = MYSQL & "FROM ((TXMASTERS INNER JOIN TXCLIPS ON TXMASTERS.ID1=TXCLIPS.ID1) "
    MYSQL = MYSQL & "INNER JOIN (AthleteNames INNER JOIN JUNCTION ON AthleteNames.AthleteID = JUNCTION.AthleteID) "
    MYSQL = MYSQL & "ON TXCLIPS.ID2 = JUNCTION.ID2) "
    MYSQL = MYSQL & "INNER JOIN KEYWORDS ON TXCLIPS.Comments Like '*' & KEYWORDS.Keyword & ' *' "
    MYSQL = MYSQL & "WHERE AthleteNames.Athlete Like [Forms]![TESTQUERIESOUT].[Form].[LA].[Caption]"
    Me.List1.RowSource = MYSQL
    </code>
    If not, see John Hutchison's suggestion.

  7. #6
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query Problem (MSACESS 2003)

    Many thanks Hans, your code worked. Sorry John, I did not see your answer slipping in. Thanks for the suggestion of showing the SQL that way, I did try using a messagebox earlier which did help show problems at the time. I remembered Hans doing it that way after I had missed out a comma in my query. Thanks both very much, best regards

  8. #7
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query Problem (MSACESS 2003)

    Sorry I'm back. Can someone tell me what this means?

    MYSQL = MYSQL & "AND Not (TXCLIPS.Shot Is Null)"

    Does it mean the query will return records if Shot has a value or not? I think it will return all records if the field shot is empty? Regards

  9. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Query Problem (MSACESS 2003)

    This line adds the condition that the Shot field should *not* be null (empty, blank), i.e. the query will only return records for which Shot has been filled in.

    BTW although

    Not (TXCLIPS.Shot Is Null)

    is perfectly valid, the "standard" way to state such a condition is

    TXCLIPS.Shot Is Not Null

  10. #9
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Query Problem (MSACESS 2003)

    Thanks Hans. Someone else had used Not (TXCLIPS.Shot Is Null), which totally confused me, I will adopt the way you show as it makes better sense when you look at it. Thanks again

Posting Permissions

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