Updating table where table name depends on combo box value

jbd83

New member
Local time
Yesterday, 18:25
Joined
Jan 17, 2014
Messages
3
Hello, I am trying to update a table with the value of a text box on the form where the table to update is as selected from a combo box on the form.

I keep getting the following

Error message:
Run-time error ‘2465’
Microsoft Access can’t find the field ‘“ & table_to_update & “’ referred to in your expression

But really can't see what I've done wrong. Have checked that the table_to_update string does contain the name of the table so guess it must be sql..

Any help much appreciated

Code:
Private Sub Command91_Click()
 Dim table_to_update, sql_string As String
  table_to_update = Me.Combo49
 Debug.Print table_to_update
 sql_string = "UPDATE [" & table_to_update &  "] SET [" & table_to_update & "].[Project] = """ &  Text89.Value & """ WHERE [" & table_to_update & "].[ID] = "  & Forms![T_entity]![" & table_to_update & "]![ID] & ""
 db.Execute sql_string
 End Sub
 
I think it is this part:
Code:
Forms![T_entity]![" & table_to_update & "]![ID]
Try:
Code:
Forms![T_entity]![ID]
Else post a print screen of the sql_string after you've assign it with the:
Code:
"UPDATE [" & table_to_update &  "] SET [" & table_to_update & "].[Project] = """ &  Text89.Value & """ WHERE [" & table_to_update & "].[ID] = "  & Forms![T_entity]![" & table_to_update & "]![ID] & ""
 

Users who are viewing this thread

Back
Top Bottom