I may be confused but I'm not passing an array to the function. The array is declared and populated in the function. The function then returns an array to a procedure.
I may be looking at this all wrong. Should I be using a public sub? Here's my code. The loop at the end involving "j" was just so I could see if it had the desired result....which is very close to what I'm looking for.
Code:
Function Gaps(curNum) As Variant
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim GapArray()
Dim strSQL As String
Dim GapCounter As Integer
Dim i As Integer
Dim j As Integer
GapCounter = 0
i = 1
strSQL = "select * from qrywinningnums"
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
ReDim GapArray(1)
Do While Not rs.EOF
If rs!one = curNum Or rs!Two = curNum Or rs!three = curNum Or rs!four = curNum Or rs!five = curNum Then
GapArray(i) = GapCounter
GapCounter = 0
i = i + 1
ReDim Preserve GapArray(i)
rs.MoveNext
Else
GapCounter = GapCounter + 1
rs.MoveNext
End If
Loop
'this is the line that throws the error
'Gaps = GapArray
j = 1
For j = 1 To 100
Debug.Print GapArray(j)
Next j
End Function