How to write an append query on a recordset

M

magicdds-

I have some code running on an event procedure. At one point in the code I
need to run an append query. If the data to be appended to the table
LETTERHISTORY was in another table, I would just have an append query and
DoCmd.OpenQuery "QueryName".

However, my data is in a recordset that was created in the code of the event
procedure.

The name of the recordset is "rstDayFile"

The Query, if made by the QUERY BUILDER would look like this:

INSERT INTO LetterHistory ( PatientID, LetterName, LetterDate )
SELECT PatientID, LetterName, Date() AS LetterDate
FROM rstDayFile;

I don't know how to type this query into the VBA code of the event procedure
or how to get it to run to append the single record to the LETTERHISTORY
table.
There are 3 fields in the LETTERHISTORY table: PatientID, LetterName,
LetterDate.

Thanks for your help.
Mark
 
A

Alex Dybenko

Hi,
to run a query you can use docmd.runsql or currentdb.execute:

strSQL="INSERT INTO LetterHistory ( PatientID, LetterName, LetterDate )
SELECT PatientID, LetterName, Date() AS LetterDate FROM rstDayFile"

currentdb.execute strSQL, dbfailonerror

Perhaps you need to add some where condition to your query

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 

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