Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81

    Syntax Error

    Can anyone tell me why I am gettng a syntax error on the following Bolded code:

    Private Sub Command18_Click()
    Dim rsc As Recordset
    Dim ClassNmb As Long


    'DoCmd.Beep
    DoCmd.SetWarnings False
    DoCmd.RunSQL "SELECT DISTINCTROW " & _
    "DepartmentData.Department, DepartmentData.Title, Employees.LastName, " & _
    "Employees.FirstName, Employees.[Employee Number], DepartmentData.[Original Hire Date] " & _
    "INTO WrkTable FROM Employees INNER JOIN DeparmentData ON Employees.DepartmentNo = DepartmentData.DepartmentNo"
    "ORDER BY DepartmentData.Department, DepartmentData.Title, Employees.LastName, Employees.FirstName;"
    DoCmd.RunSQL "ALTER TABLE WrkTable ADD COLUMN Chosen Logical;"
    DoCmd.RunSQL "ALTER TABLE WrkTable ADD COLUMN CourseNumber Long;"
    DoCmd.RunSQL "ALTER TABLE WrkTable ADD COLUMN Attended Logical;"
    DoCmd.RunSQL "ALTER TABLE WrkTable ADD COLUMN DateAttended Date;"
    DoCmd.RunSQL "UPDATE WrkTable " & _
    "SET WrkTable.CourseNumber = Forms!EdClasses!CourseNumber.Value;"

    DoCmd.OpenForm "EdEnroll"
    DoCmd.SetWarnings True

    End Sub

    Thanks in advance for your help.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    No line continuation characters?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,600
    If this is an accurate posting of your query, missing a space between DepartmentNo and ORDER BY. When the string compiles the words will run into each other. Also missing line continuation characters.

    Why do you need code that creates a new table?
    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
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    Not sure what No line continuation characters refers to but when I highlight the line of code I do get that message. What is the fix for this?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    You're missing the

    & _

    at the end of the previous line.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    June, the table is set up to enroll all employees into a class that is being offered. I'm not entirely sure how to add a space. Would this be correct?

    "INTO WrkTable FROM Employees INNER JOIN DeparmentData ON Employees.DepartmentNo = DepartmentData.DepartmentNo" +""
    "ORDER BY DepartmentData.Department, DepartmentData.Title, Employees.LastName, Employees.FirstName;"
    DoCmd.RunSQL "ALTER TABLE WrkTable ADD COLUMN Chosen Logical;"

    If so, I am still getting the same syntax error.

  7. #7
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    Thanks Paul, that did the trick. Any reason why this worked perfectly in Access 95 but not in Access 2007?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,600
    That was concatenating an empty string.
    Just type a space within the quote mark after DepartmentNo., as done on the preceding 3 lines.

    Ampersand (&) is preferred operator for concatenation. The + is holdover from ancient Basic.
    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.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Quote Originally Posted by Canadiangal View Post
    Thanks Paul, that did the trick. Any reason why this worked perfectly in Access 95 but not in Access 2007?
    Happy to help. No, and I can't believe that would have worked in previous versions, though I've never used 95.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,600
    I agree, the sql should have failed in any version.
    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.

  11. #11
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81

    Syntax Error when Calling Code

    Still getting an error but not in compiling, just when calling. This is the error: Runtime error 3131 Syntax error in From Clause
    This is the code that is highlighted

    DoCmd.RunSQL "SELECT DISTINCTROW " & _
    "DepartmentData.Department, DepartmentData.Title, Employees.LastName, " & _
    "Employees.FirstName, Employees.[Employee Number], DepartmentData.[Original Hire Date] " & _
    "INTO WrkTable FROM Employees INNER JOIN DeparmentData ON Employees.EmployeeNumber= DepartmentData.EmployeeNumber, " & _
    "ORDER BY DepartmentData.Department, DepartmentData.Title, Employees.LastName, Employees.FirstName;"

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,600
    Remove the comma after EmployeeNumber.
    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.

  13. #13
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    Made that change and now it states that I have a runtime error 3135 Syntax error in Join operation.

    DoCmd.RunSQL "SELECT DISTINCTROW " & _
    "DepartmentData.Department, DepartmentData.Title, Employees.LastName, " & _
    "Employees.FirstName, Employees.[EmployeeNumber], DepartmentData.[Original Hire Date] " & _
    "INTO WrkTable FROM Employees INNER JOIN DeparmentData ON Employees.EmployeeNumber = DepartmentData.EmployeeNumber " & _
    "ORDER BY DepartmentData.Department, DepartmentData.Title, Employees.LastName, Employees.FirstName;"

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,600
    Why do you even need code to create table?
    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.

  15. #15
    Canadiangal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2009
    Posts
    81
    The table is created on the fly, each time a new class is created an employees get enrolled in the class. Based on this enrollment, reminders are sent, certificates printed out, etc. It may be that an employee would take a class only once for certification, but then they might have to take it yearly.

    Thanks
    Tina

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-05-2013, 11:17 AM
  2. Compile Error: Syntax Error in DoCmd.RunSQL Statement
    By Evilferret in forum Programming
    Replies: 1
    Last Post: 08-27-2012, 12:32 PM
  3. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  4. Replies: 5
    Last Post: 03-27-2012, 01:40 PM
  5. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM

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