Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Type Mismatch Returning Array 1

Status
Not open for further replies.

wendyp

IS-IT--Management
Mar 4, 2003
51
US
I have several functions in my app which return arrays. Here is a clip of one that works:

'*************************************************************
Public Function GetCounts(pFullName As String, _
Optional pStartDate As Date, _
Optional pEndDate As Date) As Variant

.... bunch of code to calculate all those things....


GetCounts = Array(pFullName, pTotalOrders, pCountSales, pCountDoors, pCountGates, _
pCountWin, pCountSS, pCountSource, pTotalProducts)

rs.Close
Set rs = Nothing

End Function
'*************************************************************

So I tried a new function - maybe it's something stupid because I've been staring at it for quite a while, but I can't see a difference.

'*************************************************************
Public Function FindDups() As Variant

Dim rstLoopCust As ADODB.Recordset
Dim rstUpdateCust As ADODB.Recordset

Dim rec1 As Integer
Dim rec2 As Integer

rec1 = 0
rec2 = 0

........... bunch of code to find rec1 & rec2 ........


Debug.Print "customer #1 is: " & rec1
Debug.Print "customer #2 is: " & rec2

FindDups = Array(rec1, rec2)

End Function
'*************************************************************

Why do I get a "data type mistmatch '13'" on the second function? They're both defined at variants and both are using the "array" function to populate data.

Thanks for any help. I hate it when computers do what you tell them to and not what you mean!

/Wendy
 
I've done a test and found if you run it as ?finddups on the immediate window you get that error, because you cannot display a variable as an array.

if you run it ?finddups(1) then you will be displayed the content of index 1 of the array.

I would assume you are calling the routine and assigning the function name the data you want returned and then not handling it correctly as an array or you are testing via the immediate window and not giving the index you want to display.

hope that helps.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
THANK YOU! I knew it had to be something obvious.

I tried

?finddups(1)

and that didn't work, so I wrote a little sub to call finddups

Public Function ResolveDups() As Boolean

Dim arrRecs As Variant

arrRecs = FindDups
Debug.Print arrRecs(0)
Debug.Print arrRecs(1)

ResolveDups = False

End Function

And that worked perfectly. You get a star in my book - saved me another day of banging my head.

/Wendy
And it works!!

?fin
 
glad I could help.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top