User-Defined type error
Posted on 2004-11-23
I'm writing some VBA code that utilizes UDTs and passes them as arguments to other sub procedures. I don't have any class modules and am containing all the code within the one standard module. Problems arise on a couple of fronts: 1 - when I try to fill an array of UDTs, I get the 'Only user-defined types defined in public object modules can be coerced....' compile error.
2 - when I try to pass an array of the UDT to a sub procedure ,the compiler complains that there's a type mismatch and doesn't seem to recognise the the array I'm passing.
The relevant code is as follows:
Public Type Details
A As Variant
x As Variant
Public Type Multiple
CID As Variant
code As Variant
Dim Dets, TwWk1(), TwWk2(), TwWk3() As Details
Dim Ii, Jj, Kk, Ll, Zz, ji, ki, li, Wk1, Wk2, Wk3 As Integer
Dim AllList(), FstArr(), SecArr(), ThrArr(), mult As Multiple
Select Case (Ii)
Wk1 = Wk1 + 1
ReDim Preserve TwWk1(Wk1)
TwWk1(Wk1 - 1) = Dets ------ this assignment throws the 'Only user-defined...' error
Wk2 = Wk2 + 1
ReDim Preserve TwWk2(Wk2)
TwWk2(Wk2 - 1) = Dets
Wk3 = Wk3 + 1
ReDim Preserve TwWk3(Wk3)
TwWk3(Wk3 - 1) = Dets
Call outputdets(TwWk1(), Ii)--------this is where the type mismatch error occurs.
Sub outputdets(DetArr() As Details, Ii As Integer)
I've written similar code in other VBA modules without any problems, are there any specific scenarios where these errors are raised in bug free code or am I just missing something blindingly obvious? I must mention that the code also contains a couple of declared functions that reference the shell32.dll, could this have anything to do with it at all?
500 big ones to any helpful suggestions....