richiepr77
IS-IT--Management
I'm trying to insert records in a table with a range of dates. I've already did that with one employee on this sub.
I tried to do it with nested loops, but it runs only one record.
What I'm doing wrong?
Code:
DoCmd.SetWarnings False
Dim FirstDate, EndDate As Date, RecordNo As Long, ChangeType As String
FirstDate = Me.Date1
EndDate = Me.Date2
RecordNo = 1
ChangeType = cboTipoCambio.Value
Do While FirstDate <= EndDate
If Weekday(FirstDate, vbSunday) <> vbSaturday And Weekday(FirstDate, vbSunday) <> vbSunday Then
DoCmd.RunSQL "INSERT INTO tblMonth (RecordNo, Date, Status) VALUES (" & RecordNo & ",#" & Format(FirstDate, "mm/dd/yyyy") & "#,'" & ChangeType & "')"
End If
FirstDate = DateAdd("d", 1, FirstDate)
Loop
End Sub
I tried to do it with nested loops, but it runs only one record.
Code:
DoCmd.SetWarnings False
Dim FirstDate, EndDate As Date, RecordNo As Long, ChangeType As String
FirstDate = Me.Date1
EndDate = Me.Date2
RecordNo = 1
ChangeType = cboTipoCambio.Value
Do While RecordNo <= 366
Do While FirstDate <= EndDate
If Weekday(FirstDate, vbSunday) <> vbSaturday And Weekday(FirstDate, vbSunday) <> vbSunday Then
DoCmd.RunSQL "INSERT INTO tblMonth (RecordNo, Date, Status) VALUES (" & RecordNo & ",#" & Format(FirstDate, "mm/dd/yyyy") & "#,'" & ChangeType & "')"
End If
FirstDate = DateAdd("d", 1, FirstDate)
Exit Do
RecordNo = RecordNo + 1
Loop
End Sub
What I'm doing wrong?