I've got the following code below, which kind of does what I want but is missing something fundamental.
the runsql command inserts the right number of rows but not the right dates (its always the same date as determined by idate)
if the review_frq is quarterly and the no_years is 1 and the initial_month is 01/01/02 then I'd want (this is the bit that i can't get to work) 2 records into the table with dates of 01/01/02, 01/04/02, 01/07/02 and 01/10/02
can someone help please?????
kim
Dim myNum As Integer
Dim timesby As Integer
Dim loopby As Integer
Dim idate As Date
Dim idateadd As Integer
Dim x As Integer
If Me.review_frq = "Monthly" Then
myNum = 12
idateadd = 1
ElseIf Me.review_frq = "Quarterly" Then
myNum = 4
idateadd = 3
ElseIf Me.review_frq = "Half-Yearly" Then
myNum = 2
idateadd = 6
ElseIf Me.review_frq = "Annually" Then
myNum = 1
idateadd = 12
End If
timesby = Me.no_years
loopby = myNum * timesby
idate = DateAdd("m", idateadd, Format(Me.initial_month, "long date"
)
For x = 1 To loopby
DoCmd.RunSQL "INSERT INTO tblreview(strat_met, review_month) values(" & Me.strat_met & " , #" & Format(idate, "long date"
& "#)"
Next x
the runsql command inserts the right number of rows but not the right dates (its always the same date as determined by idate)
if the review_frq is quarterly and the no_years is 1 and the initial_month is 01/01/02 then I'd want (this is the bit that i can't get to work) 2 records into the table with dates of 01/01/02, 01/04/02, 01/07/02 and 01/10/02
can someone help please?????
kim
Dim myNum As Integer
Dim timesby As Integer
Dim loopby As Integer
Dim idate As Date
Dim idateadd As Integer
Dim x As Integer
If Me.review_frq = "Monthly" Then
myNum = 12
idateadd = 1
ElseIf Me.review_frq = "Quarterly" Then
myNum = 4
idateadd = 3
ElseIf Me.review_frq = "Half-Yearly" Then
myNum = 2
idateadd = 6
ElseIf Me.review_frq = "Annually" Then
myNum = 1
idateadd = 12
End If
timesby = Me.no_years
loopby = myNum * timesby
idate = DateAdd("m", idateadd, Format(Me.initial_month, "long date"
For x = 1 To loopby
DoCmd.RunSQL "INSERT INTO tblreview(strat_met, review_month) values(" & Me.strat_met & " , #" & Format(idate, "long date"
Next x