Question : Ms Access Codes / Expression

Dim d As Date
    Dim i As Integer
For i = 0 To 6
  CurrentDb.Execute "INSERT INTO tblPySub([Date],[driverID]) VALUES(" & DateAdd("d", i + 1, Me.StartDate) & "," & Me.DriverID & ")"
Next i

Me.frmPySub.Form.Requery


in the code above dates are not right, all records are the same date i.e Me.startDate = 8/24/10 this code needs to make 7 records 1st date would = Me.startDate, 2nd would =Me.startDate+1, 3rd Me.startDate+2, 4th Me.startDate +3, etc...
what it is out putting Me.startDate = 8/25/2010  all 7 added records are 12/30/1989

Answer : Ms Access Codes / Expression

You can try ..

CurrentDb.Execute "INSERT INTO tblPySub([Date],[driverID])
VALUES(#" & format(DateAdd("d", i + 1, Me.StartDate), "yyyy-mm-dd") & "#," & Me.DriverID & ")"

but there might be an issue with me.startdate, so before the 'For i= ... ' command add a temporary line..

msgbox me.startdate

and make sure you see what you are expecting.
Random Solutions  
 
programming4us programming4us