R
RipperT
I am trying to grab missing numbers from a sequence of numbers in an ID
field in a table using a For Next loop that will plug the missing numbers
into dynamic array. I'm working off of Access help. I've tried so many
variations of this trying to get it to work that I can't remember them all,
but here is the latest version. It generates an index out of range error
just before the Redim statement. Can anyone tell me why? Actually getting an
array to work in VBA is my focus right now because I've never been able to
create one that worked. I haven't even given any thought to what I'll do
with my array once it has actual values in it, I just want to get that far
and I'll be happy. Thanks to anyone who can help.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim lowestID As Long, highestID As Long
Dim i, j
Set db = CurrentDb
Set rs = db.OpenRecordset("qryGrievances")
Dim a() As Variant
With rs
.MoveLast
highestID = !GrievNumber
.MoveFirst
lowestID = !GrievNumber
End With
j = 0
For i = lowestID To highestID
If IsNull(DLookup("GrievNumber", "qryGrievances", "[GrievNumber] = " & i
& "")) Then
Debug.Print i
a(j) = i
ReDim Preserve a(UBound(a) + 1)
j = j + 1
End If
Next
End Function
field in a table using a For Next loop that will plug the missing numbers
into dynamic array. I'm working off of Access help. I've tried so many
variations of this trying to get it to work that I can't remember them all,
but here is the latest version. It generates an index out of range error
just before the Redim statement. Can anyone tell me why? Actually getting an
array to work in VBA is my focus right now because I've never been able to
create one that worked. I haven't even given any thought to what I'll do
with my array once it has actual values in it, I just want to get that far
and I'll be happy. Thanks to anyone who can help.
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim lowestID As Long, highestID As Long
Dim i, j
Set db = CurrentDb
Set rs = db.OpenRecordset("qryGrievances")
Dim a() As Variant
With rs
.MoveLast
highestID = !GrievNumber
.MoveFirst
lowestID = !GrievNumber
End With
j = 0
For i = lowestID To highestID
If IsNull(DLookup("GrievNumber", "qryGrievances", "[GrievNumber] = " & i
& "")) Then
Debug.Print i
a(j) = i
ReDim Preserve a(UBound(a) + 1)
j = j + 1
End If
Next
End Function