query in vb code

  • Thread starter Thread starter =?ISO-8859-1?Q?=D8ystein_Sund?=
  • Start date Start date
?

=?ISO-8859-1?Q?=D8ystein_Sund?=

Hello!

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



Sincerely
Øystein Sund
 
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
 
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
 
Back
Top