query in vb code

Ø

Øystein Sund

Hello!

I'm a little fresh to this, but how do you run a insert query in vba code?



Sincerely
Øystein Sund
 
C

chas

Hi,

something similar to the following should point you in the
right direction:

'=========
Dim strSQL As String
strSQL = "INSERT INTO TableName (Field1, Field2) values
(1,'Hello World')"
DoCmd.RunSQL strSQL
'=========

hth

chas
 
D

Douglas J. Steele

While that will work, it has the annoyance that it'll pop up a message
asking whether you really wanted to insert the values.

Perhaps better is

'=========
Dim strSQL As String
strSQL = "INSERT INTO TableName (Field1, Field2) values(1,'Hello World')"
CurrentDb.Execute strSQL, dbFailOnError
'=========

Not only does this suppress the messages, but it also allows you trap any
errors that might occur.


--
Doug Steele, Microsoft Access MVP



Hi,

something similar to the following should point you in the
right direction:

'=========
Dim strSQL As String
strSQL = "INSERT INTO TableName (Field1, Field2) values
(1,'Hello World')"
DoCmd.RunSQL strSQL
'=========

hth

chas
 

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