Syntax Error 3131 (1 Viewer)

khurram7x

Registered User.
Local time
Tomorrow, 01:59
Joined
Mar 4, 2015
Messages
226
I want to delete all records from all tables, but whenever i try the below code it shows me Run-time error 3131: Syntax error in FROM clause. Could someone direct me to the mistake I'm making please?

Dim tVar As TableDef
Dim strVar As String

For Each tVar In CurrentDb.TableDefs
If Left(tVar.Name, 4) <> "MSys" Then

'Here I've tried without WHERE clause too, but same error appears back
CurrentDb.Execute "DELETE * FROM " & tVar.Name & " WHERE ID Is Not Null"

End If
Next tVar
 

JHB

Have been here a while
Local time
Today, 21:59
Joined
Jun 17, 2012
Messages
7,732
Maybe there is a space in the table name, so try:
Code:
CurrentDb.Execute "DELETE * FROM [B][COLOR=Red][[/COLOR][/B]" & tVar.Name & "[B][COLOR=Red]][/COLOR][/B] WHERE ID Is Not Null"
 

khurram7x

Registered User.
Local time
Tomorrow, 01:59
Joined
Mar 4, 2015
Messages
226
Worked, Thanks. Another useful thing to know.

Though there are no spaces in the table name and I reassured it, but there are two blank lines in results after table names when i use Debug.Print... maybe that was the problem!
 

Users who are viewing this thread

Top Bottom