Inserting records into a table using runSQL command

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am dynamically inserting rows into a diary table to create the appointment
slots for an employee for a chosen date. The code I am using is below.
Basically it works fine, except for one small hitch, I am getting an
information prompt asking if I am sure I want to save the record after the
docmd has completed. Considering that this is supposed to be happening
invisibly behind the scenes, this is not good. Is there any way to turn off
the prompt?

dtmAppointSlot = dtmWorkStartTime
Do While dtmAppointSlot < dtmWorkEndTime

strSqlStmt = "INSERT INTO Diary " & _
"(AppointmentDate, AppointmentStartTime) VALUES ( " & _
Chr(39) & calDateChooser & Chr(39) & Chr(44) & _
Chr(39) & dtmAppointSlot & Chr(39) & " )"
DoCmd.RunSQL strSqlStmt

dtmAppointSlot = dtmAppointSlot + dtmAppointSize

Loop

Thanks
 
Hi.
Is there any way to turn off
the prompt?

Instead of the RunSQL( ) method, use the Execute( ) method of the Database
object to execute the action query silently.

Try:

<Rest of code goes here.>

Dim db As Database

Set db = CurrentDB( )
dtmAppointSlot = dtmWorkStartTime
Do While dtmAppointSlot < dtmWorkEndTime

strSqlStmt = "INSERT INTO Diary " & _
"(AppointmentDate, AppointmentStartTime) VALUES ( " & _
Chr(39) & calDateChooser & Chr(39) & Chr(44) & _
Chr(39) & dtmAppointSlot & Chr(39) & " )"
db.Execute strSqlStmt, dbFailOnError

dtmAppointSlot = dtmAppointSlot + dtmAppointSize

Loop

db.Close
Set db = Nothing

<Rest of code goes here.>

HTH.

Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address, so that a message
will be forwarded to me.)

- - -
When you see correct answers to your question posted in Microsoft's Online
Community, please sign in to the Community and mark these posts as "Answers,"
so that all may benefit by filtering on "Answered questions" and quickly
finding the right answers to similar questions. Remember that the first and
best answers are often given to those who have a history of rewarding the
contributors who have taken the time to answer questions correctly.
 
Back
Top