Hello:
I am trying to create multiple records in a table named tblTravel based on the input of a date range in two form controls. The inputs for the form are LastName, TravelDate, EndDate, Event, LocationCity, and LocationState. Everything works perfectly, except for the fact that the dates do not correctly enter into the table. For example, if I enter a date range of March 3, 2008 - March 5, 2008 and click OK, 3 records are generated. The first has the correct date (March 3, 2008), but the next two records return dates of 12-31-1899. The code I am using is pasted below. Please help!!!
[CODE=vb]Private Sub OK_onclick()
Dim i
For i = Int(CVDate(Me!f ldTravelDate)) To Int(CVDate(Me!f ldEndDate))
If (DatePart("w", i, vbMonday) <> 6) And (DatePart("w", i, vbMonday) <> 7) Then
DoCmd.RunSQL "INSERT INTO tblTravel(fldNa me,fldTravelDat e,fldEventName, fldLocationCity ,fldLocationSta te) VALUES ('" + Me!fldName + "'," + Format(i, "dd/mm/yy") + ",'" + Me!fldEventName + "','" + Me!fldLocationC ity + "','" + Me!fldLocationS tate + "');"
End If
Next i
End Sub[/CODE]
I am trying to create multiple records in a table named tblTravel based on the input of a date range in two form controls. The inputs for the form are LastName, TravelDate, EndDate, Event, LocationCity, and LocationState. Everything works perfectly, except for the fact that the dates do not correctly enter into the table. For example, if I enter a date range of March 3, 2008 - March 5, 2008 and click OK, 3 records are generated. The first has the correct date (March 3, 2008), but the next two records return dates of 12-31-1899. The code I am using is pasted below. Please help!!!
[CODE=vb]Private Sub OK_onclick()
Dim i
For i = Int(CVDate(Me!f ldTravelDate)) To Int(CVDate(Me!f ldEndDate))
If (DatePart("w", i, vbMonday) <> 6) And (DatePart("w", i, vbMonday) <> 7) Then
DoCmd.RunSQL "INSERT INTO tblTravel(fldNa me,fldTravelDat e,fldEventName, fldLocationCity ,fldLocationSta te) VALUES ('" + Me!fldName + "'," + Format(i, "dd/mm/yy") + ",'" + Me!fldEventName + "','" + Me!fldLocationC ity + "','" + Me!fldLocationS tate + "');"
End If
Next i
End Sub[/CODE]
Comment