Search code examples
vb.netms-access

Can I insert into a table using a variable instead? Using vb.net and ms access


Dim currentTable as String currentTable = studentTable

"insert into currentTable

Versus

"insert into studentTable

I want to take what the user selects in a combobox, put it in a variable, and use that in my insert statement. Instead of just hard coding the table name.


Solution

  • The following should work if you update currentTable with the name of the table you want to write to:

    command = "INSERT INTO [" &  currentTable & "] ([ClockInTime]) values ('" & Label3.Text & "')"