0

I am writing a simple piece of SQL query to update a table in my test database, but I am encountering problems:

Public Sub UpdateStatus(TypeName As String) Dim DBase As Database Dim SQLCommand As String Dim qdfChange As QueryDef SQLCommand = "Update Case SET Status = 1 WHERE TypeName = '" & TypeName & "';" Debug.Print SQLCommand Set DBase = OpenDatabase("C:\TestDatabase\CaseSet.accdb") Set qdfChange = DBase.CreateQueryDef("", SQLCommand) qdfChange.Execute End Sub 

The field names in table Case match the ones in my SQL query.

(If this is of any value, this function belongs to a form)

12
  • Are you able to run your SQL directly? Is your actual column/table names a reserved word in Access? What data type is bar and foo? Commented May 23, 2016 at 18:10
  • foo is Number, bar is Short Text Commented May 23, 2016 at 18:17
  • Is bar getting properly set? Can you put a breakpoint on the SQLCommand= line and verify that bar has a value? Commented May 23, 2016 at 18:18
  • yes bar is set properly Commented May 23, 2016 at 18:20
  • 2
    Is table name, field1? Can you actually put the SQL statement which should not reveal personal/proprietary data? Commented May 23, 2016 at 18:33

1 Answer 1

1

Case is a reserved word and TypeName is a VBA Function. That makes them poor choices for database object names.

If you can't rename them, bracket those names in your SQL statement so the db engine will recognize them as object names.

SQLCommand = "Update [Case] SET Status = 1 WHERE [TypeName] = '" & TypeName & "';" 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.