INSERT INTO SQL

1

123

Thank you for your help and answer



I have this SQL Code and I want YOU to (modify this code) to help me

What is my problem my problem is I want use the value of text0 in replace
with value of SQL statement….



More information: INSERT INTO You Should Put Actual Value “b” “C” etc Put
what I want is using The value of the text box it self



---------------------------------------------------------------------

Private Sub Command2_Click()

Dim sql As String

Dim newcolor As Variant

newcolor = Me.Text0.Value

sql = "INSERT INTO tblcolor " & "(color) VALUES " & " (newcolor);"



DoCmd.RunSQL sql
 
4

456

sql = "INSERT INTO tblcolor (color) VALUES (" & Me.Text0 & ");"

CurrentDb.Execute sql, dbFailOnError
 
D

Douglas J. Steele

456's answer will work if color is a numeric field. If it's a text field,
you'll need to use

sql = "INSERT INTO tblcolor (color) VALUES ('" & Me.Text0 & "')"

Exagerated for clarity, that's

sql = "INSERT INTO tblcolor (color) VALUES ( ' " & Me.Text0 & " ' )"

You could also use

sql = "INSERT INTO tblcolor (color) VALUES (" & Chr$(34) & Me.Text0 &
Chr$(34) & ")"

(Note that the terminating semi-colon is optional)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top