Textbox to Field in table

T

tiger

Hi,

I have an access application that I am working on, I have a form with
textbox on it; I will like to store whatever the user enter in this textbox
into a field of a table. I try the following code

INSERT INTO tblEmployee (LastName) Value (Textbox)

but this is not working because I don't know how to reference to the content
of the textbox OR Is there another way to do as in using some like button
Add Record with code DoCmd.GoToRecord.

Your help is greatly Appreciated...

Thanks
Tiger
 
D

Douglas J. Steele

Assuming you're doing this in code, you'll have to build the SQL string in
code, with the value of the textbox outside of the quotes. However, since
the name is text, you'll have to ensure that its value is surrounded with
quotes as well:

Dim strSQL As String

strSQL = "INSERT INTO tblEmployee (LastName) " & _
"Value (" & Chr$(34) & Me.Textbox & Chr$(34) & ")"

CurrentDb.Execute strSQL, dbFailOnError
 
Top