Results 1 to 5 of 5
  1. #1
    Tyork is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    35

    SQL Query

    I'm probably missing something really easy here. I have the following block of code:



    Code:
     
    If Category = "Client" Then
        SQLAddtask = "INSERT INTO CM_Task (TaskType, OpenDate, Client) VALUES('" & TType & "', #" & Date & "#, '" & CType & "')"
    ElseIf Category = "Desk" Then
        SQLAddtask = "INSERT INTO CM_Task (TaskType, OpenDate, Desk) VALUES('" & TType & "', #" & Date & "#, '" & CType & "')"
    ElseIf Category = "Group" Then
        SQLAddtask = "INSERT INTO CM_Task (TaskType, OpenDate, Group) VALUES('" & TType & "', #" & Date & "#, '" & CType & "')"
    ElseIf Category = "Campaign" Then
        SQLAddtask = "INSERT INTO CM_Task (TaskType, OpenDate, Campaign) VALUES('" & TType & "', #" & Date & "#, '" & CType & "')"
    ElseIf Category = "Project" Then
        SQLAddtask = "INSERT INTO CM_Task (TaskType, OpenDate, Project) VALUES('" & TType & "', #" & Date & "#, '" & CType & "')"
    End If
    MsgBox SQLAddtask
        DoCmd.SetWarnings False
        DoCmd.RunSQL SQLAddtask
        DoCmd.SetWarnings True
    Everything executes perfectly except for when Category = Group. I've looked at the resulting code in a message box and it looks fine to me. I get an error message stating that there is a sytax error in the INSERT INTO Statement. The entry for Group in this statment is 'G50'. Can anybody spot anything?

  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,521
    Looks okay offhand; try bracketing Group, which is a reserved word:

    [Group]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Tyork is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    35
    Thanks, I appreciate it. I'm taking a look at the list of reserved words so I don't have this issue in the future.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem (I assume that worked?). Here's a basic list:

    Reserved Words in Microsoft Access

    and a really comprehensive list:

    http://allenbrowne.com/AppIssueBadWord.html
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Tyork is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Posts
    35
    It sure did. I knew it was something easy that I was overlooking. Thanks for the help.

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

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