I get an error on line
. I have an array of variables in my table and access them using the for loop, see
. It does not seem to be working at the moment. The online example I used wasn't doing the same thing. Am I not accessing it correctly?
Private Sub btnBuild_Click()
Dim counter As Integer, thisYear As Integer, nextYear As Integer, myVacaLevel As Date, myEarnedCredits As Double
Dim EarnedField As String, UsedField As String, textBalanceField As String, prevBalanceField As String
Dim MyDB As DAO.Database, MyARec As DAO.Recordset, MyDRec As DAO.Recordset, MyVLRec As DAO.Recordset
Set MyDB = CurrentDb
Set MyVLRec = MyDB.OpenRecordset("SELECT vacationBalanceCarryOver FROM tblVacationLog where sin = '" & txtSIN & "' and vacationYear = " & txtCurrentSchoolYear & ";")
If MyVLRec.BOF And MyVLRec.EOF Then ' Empty file
Set MyDRec = MyDB.OpenRecordset("SELECT vacdue FROM dossier where nas = '" & txtSIN & "' and date = #6/30/" & txtCurrentSchoolYear & "#;")
Set MyVLRec = CurrentDb.OpenRecordset("SELECT * FROM tblVacationLog;")
With MyVLRec
.AddNew
![SIN] = txtSIN
![vacationYear] = txtYear
![vacationBalanceCarryOver] = MyDRec!vacdue
For counter = 1 To 12
EarnedField = "vacationCreditsEarned" & Format(counter, "00")
UsedField = "vacationCreditsUsed" & Format(counter, "00")
Set MyPRec = MyDB.OpenRecordset("SELECT p.class, continu, vacjr1, vacjr2, vacjr3, vacan1, vacan2, vacan3 FROM acform a, fonction f, permanen p WHERE a.nas='" & txtSIN & "' and a.nas = p.nas and p.class = fon_no;")
myEarnedCredits = MyPRec![vacjr3] / 12
!Me(EarnedField) = myEarnedCredits
Next counter
.Update
End With
Else
End If
MyDRec.Close
MyVLRec.Close
MyDB.Close
End Sub
Private Sub btnBuild_Click()
Dim counter As Integer, thisYear As Integer, nextYear As Integer, myVacaLevel As Date, myEarnedCredits As Double
Dim EarnedField As String, UsedField As String, textBalanceField As String, prevBalanceField As String
Dim MyDB As DAO.Database, MyARec As DAO.Recordset, MyDRec As DAO.Recordset, MyVLRec As DAO.Recordset
Set MyDB = CurrentDb
Set MyVLRec = MyDB.OpenRecordset("SELECT vacationBalanceCarryOver FROM tblVacationLog where sin = '" & txtSIN & "' and vacationYear = " & txtCurrentSchoolYear & ";")
If MyVLRec.BOF And MyVLRec.EOF Then ' Empty file
Set MyDRec = MyDB.OpenRecordset("SELECT vacdue FROM dossier where nas = '" & txtSIN & "' and date = #6/30/" & txtCurrentSchoolYear & "#;")
Set MyVLRec = CurrentDb.OpenRecordset("SELECT * FROM tblVacationLog;")
With MyVLRec
.AddNew
![SIN] = txtSIN
![vacationYear] = txtYear
![vacationBalanceCarryOver] = MyDRec!vacdue
For counter = 1 To 12
EarnedField = "vacationCreditsEarned" & Format(counter, "00")
UsedField = "vacationCreditsUsed" & Format(counter, "00")
Set MyPRec = MyDB.OpenRecordset("SELECT p.class, continu, vacjr1, vacjr2, vacjr3, vacan1, vacan2, vacan3 FROM acform a, fonction f, permanen p WHERE a.nas='" & txtSIN & "' and a.nas = p.nas and p.class = fon_no;")
myEarnedCredits = MyPRec![vacjr3] / 12
!Me(EarnedField) = myEarnedCredits
Next counter
.Update
End With
Else
End If
MyDRec.Close
MyVLRec.Close
MyDB.Close
End Sub