Passing Array & value to function

  • Thread starter Gord D via AccessMonster.com
  • Start date
G

Gord D via AccessMonster.com

Hi I have an array, created by a recordset, and I want to pass it to a
function along with the value. the function will check if the value is in
the array and return YES / NO
I'm getting a comile error of TypeMismatch: Array
I have a feeling the array that is created by the Getrecords is my problem
as I don't now what type it is.

Private Sub main()

Dim rs As New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "select ID from tAccounts", CurrentProject.Connection,
adOpenDynamic, adLockOptimistic
iPos = rs.RecordCount
rs.MoveFirst
aIFIS = rs.GetRows(iPos)
rs.Close

testval = "123456"
retval = ValidAccount aIFIS, testval
msgbox retval
End Sub

Private Function ValidAccount(aIFISx() As String, sValx As String)
Dim sValx As String, i As Integer
MsgBox aIFISx(i)
For i = LBound(aIFISx) To UBound(aIFISx)
If sValx = aIFISx(i) Then
sValx = "VALID"
Exit For
Else
sValx= "NOTVALID"
End If
Next i
End Function
 
A

Alex Dybenko

Try to declare aIFIS as variant, and pass it as variant to ValidAccount
instead of string
BTW, correct syntax is:
retval = ValidAccount (aIFIS, testval)
 
A

Andi Mayer..

Hi I have an array, created by a recordset, and I want to pass it to a
function along with the value. the function will check if the value is in
the array and return YES / NO
I'm getting a comile error of TypeMismatch: Array
I have a feeling the array that is created by the Getrecords is my problem
as I don't now what type it is.

Private Sub main()

Dim rs As New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "select ID from tAccounts", CurrentProject.Connection,
adOpenDynamic, adLockOptimistic
iPos = rs.RecordCount
rs.MoveFirst
aIFIS = rs.GetRows(iPos)
rs.Close

testval = "123456"
retval = ValidAccount aIFIS, testval
msgbox retval
End Sub

Private Function ValidAccount(aIFISx() As String, sValx As String)
Dim sValx As String, i As Integer
MsgBox aIFISx(i)
For i = LBound(aIFISx) To UBound(aIFISx)
If sValx = aIFISx(i) Then
sValx = "VALID"
Exit For
Else
sValx= "NOTVALID"
End If
Next i
End Function

this array has the be a variant
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top