Make a table from 2 text field on a form

J

jeanulrich00

Hi

I have a form "FrmMenu" containing 2 text fields "StartDate" and
"EndDate"

The 2 text fields are dated fields and the format is dd/mm/yyyy

Let say user put 1/1/2008 in the "StartDate" field and 31/1/2008 in
the "EndDate" field

I want to press a button and that will create a table named
"PeriodTemp" with only one field named "DatePeriod"

So when I open the table it will show

1/1/2008
2/1/2008
3/1/2008
4/1/2008

and so on until the "EndDate" 31/1/2008

What is the simpliest code I should use on the OnClick of the button

Thanks
 
A

Allen Browne

dim db As DAO.Database
dim rs as DAO.Recordset
Dim dtLoop as Date

If IsDate(Me.StartDate) And IsDate(Me.EndDate)
Set db = dbEngine(0)(0)
set rs = db.OpenRecordset("PeriodTemp", dbOpenDynaset, dbAppendOnly)
For dtLoop = CDate(Me.StartDate) To CDate(Me.EndDate)
rs.Edit
rs!DatePeriod = dtLoop
rs.Update
Next
rs.Close
Set rs = Nothing
MsgBox "Added " & db.RecordsAffected & " record(s.)"
Else
MsgBox "What dates?"
End Sub
 
P

Peter Hibbs

Allen,

I think there a couple of errors in your code.

There should be a Then at the end of the first line.
The rs.Edit should be rs.AddNew.
The End Sub should be End If.
The MsgBox shows 0 records added, not sure why as I have never used
the RecordsAffected function.

Sorry to have to correct the Master but the OP may be a bit confused.

Peter Hibbs.
 

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

Similar Threads

Create a table 1
date field on forms 1
Update Query Questions 7
How can I create a new field? 5
Modifying Date Range 2 2
Modifying Date Range 3
Dlookup 7
Advanced Filter using a range name as the criteria 1

Top