Hello,
I have the below code, which works. But it insert dates as from 1900.
This is what I am trying to do.
1). In header, there are two text fields to enter start & end date (txtDateStart / txtDateEnd). Both are formatted in "mmm d, yyyy"
2). Subform detail has option to select required records with Yes/No controls.
3). Get number of days between start & end dates.
4). INSERT INTO tblPK with selected records & dates as txtDateStart + {1+2+n = totaldays)
eg: start date: Oct 1, 2023 | End date: Oct 10, 2023
When I run with the above code it insert the dates. But they are from 1900, 7/4/1905, 7/3/1905, 7/2/1905, 7/1/1905....6/25/1905
I don't know what am I doing wrong here?
ToAccessDate: It is a function from Northwind 2.0
Any assistance would be greatly appreciated.
Raj
I have the below code, which works. But it insert dates as from 1900.
Code:
Dim dbs As DAO.Database
Dim strSQL As String
Dim i As Long
Dim TotalDays As Integer
Dim dt As Date
Set dbs = CurrentDb
dt = Me.txtDateStart
TotalDays = Me.txtDateEnd - dt + 1
For i = 1 To TotalDays
strSQL = "INSERT INTO tblSchedule (PkID, PkDate, StatusID) " & _
"SELECT PkID, " & ToAccessDate(DateAdd("d", i, dt - 1)) & " As Expr1, 0 AS Expr3 FROM tblTemp " & _
"WHERE IsSelected=-1;"
dbs.Execute strSQL, dbFailOnError
Next i
MsgBox "done", vbInformation
dbs.Close
Set dbs = Nothing
DoCmd.Close acForm, Me.Name, acSaveNo
This is what I am trying to do.
1). In header, there are two text fields to enter start & end date (txtDateStart / txtDateEnd). Both are formatted in "mmm d, yyyy"
2). Subform detail has option to select required records with Yes/No controls.
3). Get number of days between start & end dates.
4). INSERT INTO tblPK with selected records & dates as txtDateStart + {1+2+n = totaldays)
eg: start date: Oct 1, 2023 | End date: Oct 10, 2023
When I run with the above code it insert the dates. But they are from 1900, 7/4/1905, 7/3/1905, 7/2/1905, 7/1/1905....6/25/1905
I don't know what am I doing wrong here?
ToAccessDate: It is a function from Northwind 2.0
Any assistance would be greatly appreciated.
Raj