I am trying to punch into a table a bunch of dates that fall between two given dates.
When compiled,no error but when on run does not do anything..(i.e nothing in the table)
Can someone figure out what's missing?
NB: txtdate1 and txtdate2 line 23 & 15 are the date ranges entered in form frmCriteria
It should inserted all dates between these dates into table Trialdate
Thanks in advance.
Jerry
When compiled,no error but when on run does not do anything..(i.e nothing in the table)
Can someone figure out what's missing?
Code:
Option Compare Database
Option Explicit
Private Sub cmdinsert_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim counter, numdays, mynum As Integer
Dim mydate As Date
On Error GoTo ErrorHandler
Set db = CurrentDb()
Set rs = db.OpenRecordset("Trialdate", dbOpenDynaset, dbAppendOnly)
numdays = DateDiff("d", Forms!frmCriteria!txtdate1, Forms!frmCriteria!txtdate2)
[I]'will store an integer rep. days difference[/I]
counter = 0
mynum = numdays + 1
Do While counter < mynum
mydate = DateAdd("d", counter + 1, Forms!frmCriteria!txtdate1)
rs.AddNew ' go to a new record in our temp table rs
rs!InsertedDates = mydate
rs.Update
Loop
MsgBox "Already Done"
ExitHandler:
Set rs = Nothing
Set db = Nothing
Exit Sub
ErrorHandler:
Select Case Err
Case Else
MsgBox Err.Description
DoCmd.Hourglass False
Resume ExitHandler
End Select
End Sub
It should inserted all dates between these dates into table Trialdate
Thanks in advance.
Jerry
Comment