Insert unbound control via SQL string

Voltron

Defender of the universe
Local time
Today, 05:36
Joined
Jul 9, 2009
Messages
77
I have 2 unbound controls. 1 combo box and 1 textbox. The combo box is comboID and the textbox is txtPopulate. I want to send this information to 2 different fields in a table in the current database.

This is the code that I have and for some reason I keep getting an "end of statement expected" error and Access highlights the me. before the txtPopulate part.

Private Sub btnSubmit_Click()


Dim SQL As String

sql = "insert into Tbl_Analyst (Analyst_User_ID, Analyst_First_Name) values ('" & me.comboID & "','" me.txtPopulate & "')"

CurrentDb.Execute (SQL)


End Sub

What am I doing wrong?

Also, when I enter in information in the controls and hit the Submit button I get a syntax error.
 
I was missing a & before me.txtPopulate. Now I don't get either of the errors, but nothing is happening when I hit Submit.

I need to add code to open a new record upon hitting the Submit button, but am I missing anything else. Nothing is showing up in the tables when I hit the button.

I am very new to using SQL in Access so any help is greatly appreciated.
 
You missed an ampersand there.
 
Oops, typed too slowly. Change to this and see what error you get:

CurrentDb.Execute SQL, dbFailOnError
 
Oops, typed too slowly. Change to this and see what error you get:

CurrentDb.Execute SQL, dbFailOnError

That worked perfectly. I am getting an Error 3022, but this is just because I hastily threw this together (the form) and the controls are not set right for it to do it right. I am trying to allow duplicates where I can't so I can just change that.

Sorry about the edits. I hurried a bit too much with the code this morning I guess.
 

Users who are viewing this thread

Back
Top Bottom