rutime error 3219 with simple insert sql string

G

Garret Hurd

I cannot seem to get this to run in access 2k. I can do:
DoCmd.SetWarnings False
DoCmd.RunSQL StrInsertPnONLY
DoCmd.SetWarnings True

I do not understand what is wrong with
Public Sub thisisatest()
Dim db As Database
Dim strSQL As String
Dim rs As Recordset


strSQL = "insert into tbl_NextToTest (PN) values ('305-0125-006')"

Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)

End Sub



any ideas????
Thanks
 
R

Ron Weiner

Looks to me that you are attempting to use a DAO Recordset in A2k without
explicitly declaring that you want one. The default bahavious of A2k is to
use an ADO recordset. Sooo.... When you open the recordset Access is
attempting to open an ADO reordset using DAO syntax. You can either dtart
using ADO Recordsets or Set a reference to the DAO library then declare
unambigiously your intent when you need a recordset like:

dim rsDAO as DAO.Recordset
dim rsADO as ADODB.Recordset


Ron W
 
J

John Mishefske

Garret said:
I cannot seem to get this to run in access 2k. I can do:
DoCmd.SetWarnings False
DoCmd.RunSQL StrInsertPnONLY
DoCmd.SetWarnings True

I do not understand what is wrong with
Public Sub thisisatest()
Dim db As Database
Dim strSQL As String
Dim rs As Recordset


strSQL = "insert into tbl_NextToTest (PN) values ('305-0125-006')"

Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)

End Sub

Use recordsets when you want to SELECT data. For DDL type statements
(INSERT, DELETE, UPDATE, etc.) use

CurrentDb.Execute strSQL, dbFailOnError

or alternatively, DoCmd.RunSQL() call that emulates the macro RunSQL.
 

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