Append to table in VBA

  • Thread starter Thread starter Krisse
  • Start date Start date
K

Krisse

I have an unbound form for user to enter criteria for
creating a batch of records.

They enter a date range and check off one to many days of
the week.

I want to create a table containing all of the dates that
are both within the date range and are one of the selected
days of the week.

I have the loop working correctly, assigning the date to a
variable and passing over dates that are a day of the week
NOT requested, but I don't know how to write each date to
a table.

I have been looking in the VBA help but no luck finding
what I need.

Thanks!
 
Hi,
Well, normally you would use an Insert Into....
statement. If you need specifics, you'll have to post
the code you're using.
 
Thanks, John!
-----Original Message-----


Open a Recordset based on the table:

Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tablename", dbOpenDynaset)
<your loop code>
rs.AddNew ' create a new record
rs!Datefield = YourDateVariable
<add other fields as needed>
rs.Update
<end loop>
rs.Close
Set rs = Nothing


.
 
Tried the, but got error message "User-defined type not
defined" on the statement

Dim db as DAO.Database

Is there another step I need to do?

Thanks!
 
Tried the, but got error message "User-defined type not
defined" on the statement

Dim db as DAO.Database

Is there another step I need to do?

Type Ctrl-G or otherwise open the VBA editor, and select Tools...
References. Scroll down and check the reference

Microsoft DAO x.xx Object Library

(largest version).
 
Back
Top