[AccessD] Storing custom datatypes in collections

Stuart McLachlan stuart at lexacorp.com.pg
Sun Mar 21 16:21:31 CST 2004


On 21 Mar 2004 at 14:27, John W. Colby wrote:

> Has anyone ever succeeded in storing a custom data type in a collection?  I
> get an error message:
> 
> "Compile error
> 
> Only user defined types defined in public object modules can be coerced to
> or from a variant or passed to late bound functions."
> 
> This is the code I'm using:
> 
> Public Type TblDat
>     strCnn As adodb.Connection
>     strTblName As String
> End Type
> 
> Public colTest As Collection
> 
> Public Function SVTblDat(lstrCnn As adodb.Connection, lstrTblName As String)
> As TblDat
> Dim lTblDat As TblDat
>     Set lTblDat.strCnn = lstrCnn
>     lTblDat.strTblName = lstrTblName
>     SVTblDat = lTblDat
> End Function
> 
> Public Function TestCollection()
>     Set colTest = New Collection
>     colTest.Add SVTblDat(CurrentProject.Connection, "1234")
> End Function
> 
> Calling TestCollection and the error highlights SVTblDat(
> 
> Anyone?
> 

Same thing happens in VB. It's a known deficiency iin VB/VBA. 

Conventional wisdom is to use a class instead of a UDT.

Try googling on "public object module" :-(



 
-- 
Lexacorp Ltd
http://www.lexacorp.com.pg
Information Technology Consultancy, Software Development,System 
Support.






More information about the AccessD mailing list