Hi. I'm trying to add several records, 7 days apart between two dates.
This is my first attempt at coding and after lots of reading and poring over various fora I've come up with the following code which I'm using in a simple test prior to adding to my existing DB.
My problem is that the highlighted line gives a type mismatch error. I've assigned the variable 'adddate' as Date and the field 'fromdate' is formatted as short date. I'm confused.
Private Sub cmbadd_Click()
On Error GoTo Err_cmbadd_Click
Dim rs As Recordset
Dim adddate As Date
Set rs = CurrentDb.OpenRecordset("tbltest1")
adddate = fromdate
Do While adddate <= endDate
rs.AddNew
rs!bookingdate = adddate
rs!txtstart = txtstart
rs!txtend = txtend
adddate = DateAdd(D, 7, adddate + 1)
Loop
Exit_cmbadd_Click:
Exit Sub
Err_cmbadd_Click:
MsgBox Err.Description
Resume Exit_cmbadd_Click
End Sub
_________________
Until I get past this I can't see if my code is working.
Any help will be appreciated.
This is my first attempt at coding and after lots of reading and poring over various fora I've come up with the following code which I'm using in a simple test prior to adding to my existing DB.
My problem is that the highlighted line gives a type mismatch error. I've assigned the variable 'adddate' as Date and the field 'fromdate' is formatted as short date. I'm confused.
Private Sub cmbadd_Click()
On Error GoTo Err_cmbadd_Click
Dim rs As Recordset
Dim adddate As Date
Set rs = CurrentDb.OpenRecordset("tbltest1")
adddate = fromdate
Do While adddate <= endDate
rs.AddNew
rs!bookingdate = adddate
rs!txtstart = txtstart
rs!txtend = txtend
adddate = DateAdd(D, 7, adddate + 1)
Loop
Exit_cmbadd_Click:
Exit Sub
Err_cmbadd_Click:
MsgBox Err.Description
Resume Exit_cmbadd_Click
End Sub
_________________
Until I get past this I can't see if my code is working.
Any help will be appreciated.