SQL Insert?

G

Guest

Hello All,

Sorry if a double post. MS seems to be having some issues this morning.

I wanting to insert data into a table from varibles within my code. I do
this all the time when opulling data from another table, but varibles are
given me a little problem. Here is what I tried.

vSql = "insert into tbErrorHandling (ErrDesc, ErrNum, ErrOn) select " &
Err.Description & ", " & Err.Number & ", " & Err.Source & ""

docmd.Run(Vsql)

How do I pass varibles?
 
G

Guest

You need to enclose the Text values within apostrophes for the SQL statement
to be valid:

vSql = "insert into tbErrorHandling (ErrDesc, ErrNum, ErrOn) select '" &
Err.Description & "', " & Err.Number & ", '" & Err.Source & "'"

Good luck!

Steve.
 
G

Guest

Try using Values instead of Select

vSql = "insert into tbErrorHandling (ErrDesc, ErrNum, ErrOn) Values(" &
Err.Description & ", " & Err.Number & ", " & Err.Source & ")"

Also if the values are text you need to add single column to them

vSql = "insert into tbErrorHandling (ErrDesc, ErrNum, ErrOn) Values('" &
Err.Description & "', '" & Err.Number & "', '" & Err.Source & "')"
 

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