Results 1 to 6 of 6
  1. #1
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237

    VBA Compile error: End of statement

    Hi,
    I have the following in VBA Code:

    strSELECT = _
    "SELECT tblBooks.pkBookId, tblBooks.BookTitle, tblBooks.Subtitle, tlkpPublishers.PublisherName, tlkpFormats.FormatType, " _


    & "tlkpCategories.CategoryName, ConcatRelated([AuthorName],[qryBooksAuthors],[fkAuBookId]= & [pkBookID]) AS MyAuthor, " _
    & "concatrelated([keyWords],[qryBooksKeywords],fkBookId = & [pkBookID]) AS MyKeyWords, tblBooks.YearPublished, tblBooks.CallNumber " _
    & "FROM tlkpCategories INNER JOIN (tblKeyWords INNER JOIN (tblAuthors INNER JOIN (tlkpPublishers INNER JOIN (tlkpFormats " _
    & "INNER JOIN ((tblBooks INNER JOIN trelBooksKeywords ON tblBooks.pkBookId = trelBooksKeywords.fkBookId) INNER JOIN trelBooksAuthors " _
    & "ON tblBooks.pkBookId = trelBooksAuthors.fkAuBookId) " _
    & "ON tlkpFormats.pkFormatId = tblBooks.fkformatId) ON tlkpPublishers.pkPublisherId = tblBooks.fkPublisherId) " _
    & "ON tblAuthors.pkAuthorId = trelBooksAuthors.fkAuthorId) ON tblKeyWords.pkKeyWords = trelBooksKeywords.fkKeyWords) " _
    & "ON tlkpCategories.pkCategoryId = tblBooks.fkcategoryId "

    I am getting an "End of statement error" and the AuthorName is highlighted.
    I cannot find the error.

    Khalil
    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    If you build it in the query design,you won't get an error.
    no need to type SQL.

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Alternatively, use debug.print selectsql and copy and paste the resulting sql line in here.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    xxxxxxxxxx

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The error is here:

    ConcatRelated([AuthorName],[qryBooksAuthors],[fkAuBookId]= & [pkBookID])

    The syntax of that function is incorrect - ConcatRelated is a function (I have never used it but I know what it does). Its three parameters are field/table NAMES as character strings, but your SQL would give it VALUES. The field and table names would have to be in quotes:

    ConcatRelated('[AuthorName]','[qryBooksAuthors]','[fkAuBookId] = ' & [pkBookID])

    I cannot be sure the last one is right, though.

    BTW, your SQL statement compiles for me, too, so I can't say where your end of statement error is coming from.

  6. #6
    Khalil Handal is offline Competent Performer
    Windows 10 Access 2003
    Join Date
    Jun 2016
    Posts
    237
    Thanks John,
    I was missing the quotes.

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

Similar Threads

  1. Compile error: Expected end of statement
    By ritati in forum Macros
    Replies: 1
    Last Post: 12-05-2014, 05:33 AM
  2. Replies: 7
    Last Post: 07-24-2013, 02:01 PM
  3. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  4. Replies: 1
    Last Post: 06-20-2012, 12:44 PM
  5. compile error: expected end of statement
    By RedGoneWILD in forum Programming
    Replies: 5
    Last Post: 07-29-2010, 10:12 AM

Tags for this Thread

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