Results 1 to 4 of 4
  1. #1
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26

    Syntax Error when running delete SQL

    Hey,

    I'm having a problem with my SQL statement and I'm not entirely sure what I did wrong. Does it not like spaces in a table name?
    Intent of the form is for the admin to delete a record by selecting the GCAS (essentiallly a product/catalog #) they want to delete.

    GCAS Table is a table
    [GCAS ID] is the field name in the table
    cbGCAS is a combo box in a subform where the user selects the GCAS to be deleted.

    Code:
    strSQL = "Delete * From GCAS Table Where [GCAS ID]=" & Forms!AdminFunctions!NSfAdminFunctions.Form!cbGCAS
    Immediate window for ?strSQL
    Code:
    Delete * From GCAS Table Where [GCAS ID]=95128706
    Error message:
    Click image for larger version. 

Name:	DeleteGCAS Error.png 
Views:	9 
Size:	7.4 KB 
ID:	24549

    The delete statement works elsewhere in my program so I'm not entirely sure why this one is giving me a problem

    Thanks,
    -Matt

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    if the [GCAS ID] is a string field, you will get the error. so you must add the quotes

    strSQL = "Delete * From [GCAS Table] Where [GCAS ID]='" & Forms!AdminFunctions!NSfAdminFunctions.Form!cbGCAS & "'"

    if GAS TABLE is the name of the table, you must use brackets
    [GCAS Table]


    (don't put spaces in table names , fieldnames, etc, when naming them)

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    or if GCAS is the name of your table - remove the word table

  4. #4
    TheKillerMonkey is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2016
    Posts
    26
    Awesome! thanks, adding the brackets helped.

    GCAS Table is the name of the table because when I started this project I had a poor sense of naming conventions and never went back to update it.

    Thanks again for the help

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

Similar Threads

  1. Replies: 7
    Last Post: 04-01-2014, 03:38 PM
  2. running select query in form delete event
    By suki360 in forum Programming
    Replies: 0
    Last Post: 03-11-2011, 10:11 AM
  3. running sum? help? syntax error?
    By manos39 in forum Queries
    Replies: 0
    Last Post: 02-15-2011, 07:32 AM
  4. Incomplete Syntax Clause (syntax error)
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-11-2010, 10:47 AM
  5. Running a Delete (Records) Query on Close
    By NoiCe in forum Queries
    Replies: 1
    Last Post: 07-12-2009, 06:17 PM

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