G
Guest
I keep getting this error message when running the following code, which is
designed to count the number of records for a given ID in a given year, and
write that number in the appropriate field in a table. The whole code goes
from 1987-2006, but I have truncated it to 1987-1989 for assistance.
Sub ProgramMarkFile()
Dim db As DAO.Database
Dim rst1 as Recordset
Dim rst2 as Recordset
Dim CurrentID As String
Dim TempYr as Integer
Dim sSQL as String
Dim Yr87 As Integer
Dim Yr88 As Integer
Dim Yr89 As Integer
Set db = CurrentDb()
Set rst2= db.OpenRecordset("AkepMark",dbOpenDynaset
rst2.Sort = "[BANDNUM],[EvDate]"
Set rst2 = rst2.OpenRecordset
Set rst1 = db.OpenRecordset("MarkAkepInPut", dbOpenDynaset)
Yr87=0
Yr88=0
Yr89=0
rst1.MoveFirst
Do Until rst1.EOF
CurrentID = rst1!Bandnum
sSQL = "[BANDNUM] = '" & CurrentID & "'"
rst2.FindFirst sSQL
Do While rst2!Bandnum = CurrentID
TempYr = Year(rst2!EvDate)
Select Case TempYr
Case 1987
Yr87 = Yr87 + 1 ## This the line where the error occurs
Case 1988
Yr88 = Yr88 + 1
Case 1989
Yr89 = Yr89 + 1
End Select
Loop
rst1.Edit
rst1!Y87 = Yr87
rst1!Y88 = Yr88
rst1!Y89 = Yr89
rst1.Update
rst1.MoveNext
Yr87=0
Yr88=0
Yr89=0
Loop
Then a couple of closing and nothing statements.
I think that all the variables I have defined as integers should make the
statement Yr87 = Yr87 + 1 also an integer. But this is where the error is
indicated.
Thanks,
LAF
designed to count the number of records for a given ID in a given year, and
write that number in the appropriate field in a table. The whole code goes
from 1987-2006, but I have truncated it to 1987-1989 for assistance.
Sub ProgramMarkFile()
Dim db As DAO.Database
Dim rst1 as Recordset
Dim rst2 as Recordset
Dim CurrentID As String
Dim TempYr as Integer
Dim sSQL as String
Dim Yr87 As Integer
Dim Yr88 As Integer
Dim Yr89 As Integer
Set db = CurrentDb()
Set rst2= db.OpenRecordset("AkepMark",dbOpenDynaset
rst2.Sort = "[BANDNUM],[EvDate]"
Set rst2 = rst2.OpenRecordset
Set rst1 = db.OpenRecordset("MarkAkepInPut", dbOpenDynaset)
Yr87=0
Yr88=0
Yr89=0
rst1.MoveFirst
Do Until rst1.EOF
CurrentID = rst1!Bandnum
sSQL = "[BANDNUM] = '" & CurrentID & "'"
rst2.FindFirst sSQL
Do While rst2!Bandnum = CurrentID
TempYr = Year(rst2!EvDate)
Select Case TempYr
Case 1987
Yr87 = Yr87 + 1 ## This the line where the error occurs
Case 1988
Yr88 = Yr88 + 1
Case 1989
Yr89 = Yr89 + 1
End Select
Loop
rst1.Edit
rst1!Y87 = Yr87
rst1!Y88 = Yr88
rst1!Y89 = Yr89
rst1.Update
rst1.MoveNext
Yr87=0
Yr88=0
Yr89=0
Loop
Then a couple of closing and nothing statements.
I think that all the variables I have defined as integers should make the
statement Yr87 = Yr87 + 1 also an integer. But this is where the error is
indicated.
Thanks,
LAF