View Full Version : running append queries from VB


chris klein
11-12-2003, 10:34 AM
I am using an event procedure attached to a command button in a form to append a new record into each of a set of ten tables. An example of the appending code is

DoCmd.RunSQL "INSERT INTO [PROJECTS-Figures] ( [PROJID] )" & _
"VALUES (" & PRJID & "); "

This gets repeated ten times, each for a different table.

Before executing each append, Access presents me with a warning window "You are about to append 1 row(s)....Once you click yes...." with Yes and No response buttons. As a result, I have to click Yes ten times to complete the set of 10 appends.

Is there any way to suppress the warning and have the query proceed without it?

dcx693
11-12-2003, 10:49 AM
You may want to search the forum next time as this question has been answered several times (including at least two by me :) ).

Anyway, first you can manually turn the warning message off using:
DoCmd.SetWarnings False
and then turning it back on using
DoCmd.SetWarnings True
after the query has been run.

Also you can use the "Execute" method instead and it will not give you any warnings.

If you're using DAO: Currentdb.Execute SQL string or stored query name

If you're using ADO: CurrentProject.Connection.Execute SQL string or stored query name

chris klein
11-12-2003, 11:16 AM
Thanks, works perfectly.
I have a related question:
I want to be able to abort the appending process if it turns out that it already has been done, so I place DoCmd.SetWarning False AFTER the first DoCmd INSERT INTO.. This way, if the INSERT INTO finds itself trying to make a duplicate entry (into an indexed field that does not allow duplicates), I get an error message and the rest of the process aborts.

The Access/VB generic error message that is provided by use of
MsgBox Err.Description
is, however, not very clear. So, I tried commenting this line out,
( ' MsgBox Err.Description)
and replacing it with a custom
MsgBox(" ...."). But I find that the generic message STILL appears, before my new message. Is there a way to suppress the generic message?

dcx693
11-12-2003, 12:09 PM
Again a search of the forum can often turn up some good stuff, like this: Duplicates error message (http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=51996).