2

I've no problems when deleting * records from local tables in my 2010 access db, but as I loop through my list and hit linked tables (local db, this is a fe/be setup) it fails with: Run-time error '3131': Syntax error in FROM clause. code:

    If sanityCheck2 = vbYes Then
        DoCmd.SetWarnings False
       'list the tables to purge here
        dalist = "tblLocal1 tblRemote-2 tblRemote-3"
        darray = Split(dalist, " ")
        For i = LBound(darray) To UBound(darray)
           DoCmd.OpenTable darray(i)
           DoCmd.RunSQL squirrel
        Next
        DoCmd.SetWarnings True

code works fine on tblLocal1, just not on any of the remotes.

I can open the table in datasheet and delete records no prob, just not through here.

4
  • Could you show the SQL command that is in "squirrel"? Commented Sep 29, 2014 at 15:18
  • If there is a syntax error in an SQL command then show us this SQL command! We cannot fix syntax errors if no syntax is visible. Commented Sep 29, 2014 at 15:20
  • When you are finished with the first item in your array (tblLocal1) are you 100% sure tblRemote-2 is executing the same way you are thinking? Is that your real table name? And of course, we need to see the SQL. Commented Sep 29, 2014 at 15:27
  • @paulstock squirrel for the first table that throws the error is : DELETE * FROM tblRemote-2 pretty vanilla.... Commented Sep 29, 2014 at 18:50

1 Answer 1

5

I bet this is choking on the SQL you build around table names with - inside them. SQL will see DELETE * FROM tblRemote-2 WHERE ... as DELETE * FROM tblRemote - 2 WHERE ... (non-sensical subtraction) unless you wrap your table names with square brackets. Change that to DELETE * FROM [tblRemote-2] WHERE ... and you should be fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Applies to table names with spaces in them too!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.