I'm working in Access 97. I've created a custom class and collection. In the collection is the standard bit of code:-
Public Property Get NewEnum() As Iunknown
'this property allows you to enumerate
'this collection with the For...Each syntax
Set NewEnum = mCol.[_NewEnum]
However, it won't compile this, claiming that Iunknown is an unknown user defined type. I'm guessing that there is some component I'm missing. Every example of this type I've found shows the above property definition, and I need it for the For..Each..Next.. loop.
what is Iunknown defined as?
is it and enum, a user defined type a user defined class?
Effectively you are using Iunknown as a user defined variable which could be any one of a number of guises
You need to have declared Iunknown as a public <whatever> in a module if its in a commom function. If its only used in a single form / report then it can be defined in that element
I often define my own user types especially for constants (as enumerations), it doesn't do anything magical, it just makes the code easier to read. I also very occasionaly define a type to create a structure (or something similar), although I would normally use a class these days
Public Enum e_UserError 'return code on a class validation
isOK = True
isNotOK = False
isMuppet = 1 'user has done something stupid
public Type NMEARecord
Lat as double
Long as double
EventTime as date
As I said, the Iunknown is used in a few examples I saw, and they hadn't set up anything extra. However, I found that once I added a reference to "OLE Automation" the module compiled OK, so I'm guessing that Iunknown is handled in there.
I got arounf the problem with the For Each by using a slightly different construction.
Set objThisRec = New clsAuditRec
Dim i As Variant
'Load each record (object) from the collection and load into the audit table.
For i = 1 To colAudits.Count
Set objThisRec = colAudits.Item(i)
WriteAuditUpdate .sTableNm, .sKeyNm, .vRecordID, .sFieldNm, .vBefore, .vAfter
And this works the way I want it to. Still, it's a bit confusing, I was working off this example