VBA Excel: "Incompatible Byref argument type" when passing Variant Array, from Sub / to Function

Asked

Viewed 63 times

0

Claim: - Functions to calculate from an Array. Problem: - Error in 2.2. (below). Dice:

  1. Public Type varVar declares 2 variables Variant: varLatest ... last record of tables varAaD ... Function result

  2. Public Sub declares the variables: varSQL ... Select from tables arrVar() As varVar strPath ... path of base . accdb cnConn As ADODB.Connection rsRec7 As ADODB.Recordset

2.1. After declaring their initial values, connecting, etc., gets the last reg. of the tables: rsRec7.Cursortype = adOpenKeyset For i = Lbound(varSQL) To Ubound(varSQL) rsRec7.Open varSQL(i), cnConn rsRec7.Movelast arrVar(i). varLatest = rsRec7.Absoluteposition rsRec7.Close ... Debug.Print displays values: Success! Next intNum

2.2. We have values, the connection closes, time to pass Array to Function => Title Error: "Compilation error: Incompatible Byref argument type" varAaD = fxCol_A(arrVar())

  1. Function is: (e.g. the product of the numbers/position of the last table record) Public Function fxCol_A(Byref arrVar2 As varVar) Dim lngProduct As Long For i = 0 To Ubound(arrVar2) lngProduct = lngProduct * Clng(arrVar2(i).varLatest) Next i fxCol_A = Cvar(lngProdut) End Function

Thanks for the support!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.