DoCmd Options

R

Rob

Hi all,

After reading through a few of these posts I feel that I have been using a
heavy handed approach to adding data to some table. I have been creating a
recordset and then adding a new record and finally updating. This always
felt like overkill as I did not do anything with the recordset rather than
add data to it.

Anyway to my question. I have decided to replace a lot of the
rs.AddNew/rs.Update commands with DoCmd.RunSQL (INSERT INTO ...).

I actuallu have two questions about DoCmd. Is it possible to execute this
command without the built in dialog box informing me that I am about to
append rows and if I have to use this how do I respond to the cancel button.
I have had a search through the help files and also Acc97 Dev Handbook (I am
restricted to Acc97 by works current version of Office) but have been unable
to locate the answers. Any help (or comment on my method for that matter )
would be appreciated,

Thanking you
Rob
 
D

Deville

A better way of doing what you want is to use db.execute,
using this method the dialog box will no appear.

dim db as dao.database

set db = currentdb

db.execute "SQL STATEMENT", dbfailonerror

db.close
set db = nothing

or just use currentdb, it works the on the same principle
you just dont have to set a variable or reference the
database object

currentdb.execute "SQL STATEMENT"

Hope this is helpful 4 u...
 
D

Dorian

I recommend you use ADO (get a book on it), all you need to do i
Dim strSQL as strin
strSQL = "INSERT......
CurrentProject.Connection.Execute strSQ
I believe this is more efficient than a DOCM

But you can also d
DOCMD.RUNSQL strSQ

but then you get a warning message which has to be suppressed e.g.
DOCMD.SetWarnings Fals
DOCMD.RUNSQL strSQ
DOCMD.SetWarnings Tru

Hope this helps
 
R

Rob

Thanks all for your prompt assistance and suggestions. I am implementing
Devilles recommendations wrapped up in conditional statements as well error
handling routines. Seems somewhat more elegant than the previous way I was
adding data!

Cheers
Rob
 

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