Make a table from 2 text field on a form

  • Thread starter Thread starter jeanulrich00
  • Start date Start date
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
 
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
 
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.
 
Back
Top