Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004

    Unanswered: Iunknown is unknown data type...

    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]
    End Property

    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.

    Any ideas?

  2. #2
    Join Date
    Nov 2004
    OK, I've solved that problem. I needed to add a reference to "OLE Automation"

    I'm still unable to run the "For..Each.." statement though. It fails at that point saying "Run-Time Error '438'. Object does not support this property or method".

    It's driving me batty, and there's no one around here I can ask at the moment.

  3. #3
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    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
    end enum

    public Type NMEARecord
    Lat as double
    Long as double
    EventTime as date
    end type

  4. #4
    Join Date
    Nov 2004
    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)
    With objThisRec
    WriteAuditUpdate .sTableNm, .sKeyNm, .vRecordID, .sFieldNm, .vBefore, .vAfter
    End With

    And this works the way I want it to. Still, it's a bit confusing, I was working off this example

    And it doesn't mention any other references that need to be added (or not that I've been able to find. I'm probably missing something fairly basic here.

    Anyway, I've got the program doing what I want so no worries.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts