Help with docmd.runsql

homer2002

Registered User.
Local time
Today, 22:31
Joined
Aug 27, 2002
Messages
152
Can you use docmd.runsql with an INSERT INTO command like this...

first I open the database and a recordset.
then I do some stuff, but I would like to be able to use a line like

docmd.runsql "INSERT INTO [tblMsg] (User) VALUES('HELLO');"

although it won't find tblmsg. (i am trying to NOT link it with access' database splitter as the security is damn weak!)

___________________________________________________
Dim dbs As Database
Dim rst As Recordset
Dim TheLastFieldValue As String
Dim iStartCounter As Long
Dim iCounter As Long
Dim TheFieldName As String


Set dbs = DBEngine.Workspaces(0).OpenDatabase("N:\MsgBackend.mdb")
Set rst = dbs.OpenRecordset("tblMsg")
rst.MoveFirst
iStartCounter = rst.RecordCount - 5
If iStartCounter < 1 Then iStartCounter = 1
Rem Do some stuff
rst.MoveNext
Next iCounter
___________________________________________________
 
Docmd functions correspond to Menu Items in Access.

Since the table is not in your Front End (FE) and you are opening a recordset from an Outside MDB, look into the Database.Execute Command.

dbs.Execute "INSERT INTO [tblMsg] (User) VALUES('HELLO');"
 
You should be able to use the Execute method of your database object to run the sql.

dbs.Execute ("supplied sql")

Or something close to that. I use A2K and ADO so your exact syntax may differ slightly.
 

Users who are viewing this thread

Back
Top Bottom