creating table data - date() + 14

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

When a database opens up I want a table created
containing one field [date] and 14 instances which
include the date the database is opened and the following
13 days.

I understand VB.Net and how to use a Do Until Loop but do
not know how to use this type of thing in Access.

I appreciate any help you can offer. Thanks.
 
Hi Steve

The code that follows will do it for you.

Maurice

Dim mydb As Database
Dim myset As Recordset
Dim i
Dim firstdate As Date
Dim lastdate As Date
firstdate = date()
lastdate = date() + 14
Set mydb = CurrentDb
Set myset = mydb.OpenRecordset("table1")

For i = firstdate To lastdate
myset.AddNew
myset![BookingDate] = i
myset.Update
Next i
myset.Close
MsgBox "Date creation done..."
 
I tried this and received the following error User defined type not defined on the Dim mydb as Database.
 
Hi

Please make sure you have a reference to DAO in your project. Click Tools
References in your Visual Basic Editor and make sure you have a reference to
"Microsoft DAO 3.6 Object Library"

In code type as
Dim db as DAO.Database.

See if this helps.

Regards,

Naresh Nichani
Microsoft Access MVP

Bob said:
I tried this and received the following error User defined type not
defined on the Dim mydb as Database.
 
Back
Top