Implementing IUnknown interface in Access 2000 class 
Author Message
 Implementing IUnknown interface in Access 2000 class

I am trying to implement a class originally developed in
VB6 into Access 2000 and having a problem with a property
not recognizing the IUnknown interface.  I keep getting an
error condition whenever this property is accessed.  It is
pretty involved but the simple question is how do I get
Access 2000 to recognize a property defined as IUnknown?  
Works great when run through VB6...dies when same code run
in Access 2000. Here is code.

Public Property Get NewEnum() as IUnknown
     Set NewEnum = mcol.[_NewEnum]
End Property

Private Sub Class_Initialize()
    Set mcol = New Collection
End Sub

Thanks in advance
Chuck



Sun, 16 Oct 2005 23:51:13 GMT  
 Implementing IUnknown interface in Access 2000 class
What error do you receive?  I, too, use that to achieve
For Each ... Next capabilities on collection classes.

So far so good for me (same platform as yours, VB6 to
A2K), but I certainly don't want to distribute flaky code,
especially when another workaround is easy (such as
directly expose the collection object, which has the
native interface to the Enumerator object -- or otherwise
just use a counter).

One of my concerns was MS Access does't allow the ability
to specify the Procedure ID to be -4 (nor hide it, but who
cares about that).  So I've been tenuous to bless my port
that otherwise appears to work fine when using For
Each ... Next.

David Atkins, MCP



Mon, 17 Oct 2005 03:29:13 GMT  
 Implementing IUnknown interface in Access 2000 class
I decided to keep my _NewEnum feature in my Access 2000
class ported from VB.  The For Each...Next works for me,
even though I've had to /decompile this database a couple
of times now.

I'll keep an eye on it.

Please tell me the error you are receiving.

David Atkins, MCP



Mon, 17 Oct 2005 10:14:01 GMT  
 Implementing IUnknown interface in Access 2000 class
Hi David

Thanks for the response.  I am getting an error code
438 "Object doesn't support this property or method."
When I run in VB, the flow instantiates the object then
goes to the GetEnum property so can loop through
collection class but in Access it goes to the Terminate
event instead.  I assume because of the error condition
but it doesn't seem to even recognize the GetEnum
property.  You mention decompiling the Access app.  What
does that buy you and how is that done?  I'm a VBer who is
slogging around in Access, so not familiar with this.
Thanks
Chuck

Quote:
>-----Original Message-----
>What error do you receive?  I, too, use that to achieve
>For Each ... Next capabilities on collection classes.

>So far so good for me (same platform as yours, VB6 to
>A2K), but I certainly don't want to distribute flaky
code,
>especially when another workaround is easy (such as
>directly expose the collection object, which has the
>native interface to the Enumerator object -- or otherwise
>just use a counter).

>One of my concerns was MS Access does't allow the ability
>to specify the Procedure ID to be -4 (nor hide it, but
who
>cares about that).  So I've been tenuous to bless my port
>that otherwise appears to work fine when using For
>Each ... Next.

>David Atkins, MCP
>.
>Hi David

T


Mon, 17 Oct 2005 20:43:28 GMT  
 Implementing IUnknown interface in Access 2000 class
This is sounding a little flakey.

Does it execute the GetEnum at all?  Or does it err at the
For Each... line?

I am confused by what you mean when you say, "...then goes
to the GetEnum property so can loop through collection
class..."  Would you mind posting your code for the
section that uses the GetEnum?  Of course, an example of
mine might be:

Dim cAttachment as clsAttachment

For Each cAttachment in mAttachments
  msgbox cAttachment.FileName
Next cAttachment

Where mAttachments is a collection class containing the
GetEnum routine to implement the For Each...Next.

/decompile is a run-line command option (that I learned
about from this newsgroup).  A couple of times I've not
been able to view the code, apparently due to corruption.  
This fixed it.

Use Start->Run.  [path_to_access]\msaccess.exe
[your_mdb] /decompile.

I would have to say the only difference between my
collection classes and yours is I instantiate the
collection object when I Dim it.

e.g.,
Dim mcolAttachments as New Collection

Otherwise, I see no differences.  The enumeration *does*
work for me.  The jury is still out on this one for me.

David Atkins, MCP



Mon, 17 Oct 2005 22:15:27 GMT  
 Implementing IUnknown interface in Access 2000 class
Flakey it is.  I know what's happening I just don't know
why.  Counting on a knowledable Access developer to set me
straight.

I'll try to explain.

The code that it fails on is the For Each... statement.
Here is some code snipets to look at

StyleInstance = class that stores an instance of a Word
document style
StyleInstances = class that stores collection of
StyleInstance objects
DocStyles = variable ref to DocumentStyleInformation
class. This is a container for the StyleInstances
collection object.

Code Flow

Set dsiCurrent = New DocumentStyleInformation
     Class_Initialize (in documentStyleInformation class)
        Set mvarStyleInstances = New StyleInstances
     Class_Initialize (in StyleInstances class)
        Set mcol = New Collection

For Each siCurrent In DocStyles.StyleInstances
    Do some stuff
Next

On the For Each statement, it does the following

In VB6
        Public Property Get StyleInstances() As
StyleInstances
          Set StyleInstances = mvarStyleInstances
        End Prop

        Public Property Get NewEnum() as IUnknown
          Set NewEnum = mcol.[_NewEnum]
        End Prop
        (return to For Each stmt)

In Access2k
        Public Property Get StyleInstances() As
StyleInstances
          Set StyleInstances = mvarStyleInstances
        End Prop
        Class_Terminate (in DocumentStyleInformation class)
          Set mvarStyleInstances = Nothing
        Class_Terminate (in StyleInstances class)
          Set mcol = Nothing
        (goes to Error Handler code in calling object)

I know that there must be something that Access is doing
(or not doing) so that the ENUM property is ignored.  The
code is exactly the same, in both VB and Access with
exception that classes reside in Access - no difference.  
This is probably more than you need to take on but I have
been fighting this for two days and really want to keep my
for each statements.  However I may have to set up a
counter and do it that way...cause I need to get this app
finished.  I know the logic works...so ????

Thanks for any advice/assistance

Chuck          

Quote:
>-----Original Message-----
>This is sounding a little flakey.

>Does it execute the GetEnum at all?  Or does it err at
the
>For Each... line?

>I am confused by what you mean when you say, "...then
goes
>to the GetEnum property so can loop through collection
>class..."  Would you mind posting your code for the
>section that uses the GetEnum?  Of course, an example of
>mine might be:

>Dim cAttachment as clsAttachment

>For Each cAttachment in mAttachments
>  msgbox cAttachment.FileName
>Next cAttachment

>Where mAttachments is a collection class containing the
>GetEnum routine to implement the For Each...Next.

>/decompile is a run-line command option (that I learned
>about from this newsgroup).  A couple of times I've not
>been able to view the code, apparently due to
corruption.  
>This fixed it.

>Use Start->Run.  [path_to_access]\msaccess.exe
>[your_mdb] /decompile.

>I would have to say the only difference between my
>collection classes and yours is I instantiate the
>collection object when I Dim it.

>e.g.,
>Dim mcolAttachments as New Collection

>Otherwise, I see no differences.  The enumeration *does*
>work for me.  The jury is still out on this one for me.

>David Atkins, MCP
>.



Tue, 18 Oct 2005 01:14:50 GMT  
 Implementing IUnknown interface in Access 2000 class
A little hard to read.  I apologize if I am incorrect.

I looks like you're trying to return StyleInstance classes
from your StyleInstances collection class that is wrapped
in your class DocStyles.  But I don't see your Enum in
your StylesInstances class, rather it appears to be in
your DocStyles class.

Here's a hacked version of mine that works.

--- CLASS clsAttachment
Private mstrFilename As String

Public Property Let Filename(strFilename As String)
    mstrFilename = strFilename
End Property

Public Property Get Filename() As String
    Filename = mstrFilename
End Property

--- CLASS clsAttachments  (collection holder)
--- This is the class with the enumerator
Private mcolAttachments As New Collection

Public Function Add(strFilename As String) As clsAttachment

    ' add the new attachment
    Dim cAttachment As New clsAttachment
    cAttachment.Filename = strFilename
    mcolAttachments.Add cAttachment
    Set Add = cAttachment

End Function

Public Function Count() As Long
    Count = mcolAttachments.Count
End Function

Public Sub Remove(intItem As Integer)
    mcolAttachments.Remove intItem
End Sub

Public Function Item(intItem As Integer) As clsAttachment
    Item = mcolAttachments.Item(intItem)
End Function

Private Sub Class_Terminate()
    Set mcolAttachments = Nothing
End Sub

Public Function NewEnum() As IUnknown
    Set NewEnum = mcolAttachments.[_NewEnum]
End Function

--- CLASS clsEmailer (the one that uses cAttachments)
Public mAttachments As New clsAttachments

Private Sub EncodeAttachments()
    Dim cAttachment As clsAttachment

    For Each cAttachment In mAttachments
      ...
    Next cAttachment
End Sub



Tue, 18 Oct 2005 04:16:59 GMT  
 Implementing IUnknown interface in Access 2000 class
Sorry I was not more clear with my example.
The NewEnum is in the StyleInstances class.  The main
difference I see is that you use it as a method, where I
am using it as a property.  I will look at your examples
and re-think my approach...what still bothers me though is
why does it work as intended in VB6?  Thanks for all your
help.  Once I get it resolved, I will post a message under
same subject title.

Chuck

Quote:
>-----Original Message-----
>A little hard to read.  I apologize if I am incorrect.

>I looks like you're trying to return StyleInstance
classes
>from your StyleInstances collection class that is wrapped
>in your class DocStyles.  But I don't see your Enum in
>your StylesInstances class, rather it appears to be in
>your DocStyles class.

>Here's a hacked version of mine that works.

>--- CLASS clsAttachment
>Private mstrFilename As String

>Public Property Let Filename(strFilename As String)
>    mstrFilename = strFilename
>End Property

>Public Property Get Filename() As String
>    Filename = mstrFilename
>End Property

>--- CLASS clsAttachments  (collection holder)
>--- This is the class with the enumerator
>Private mcolAttachments As New Collection

>Public Function Add(strFilename As String) As
clsAttachment

>    ' add the new attachment
>    Dim cAttachment As New clsAttachment
>    cAttachment.Filename = strFilename
>    mcolAttachments.Add cAttachment
>    Set Add = cAttachment

>End Function

>Public Function Count() As Long
>    Count = mcolAttachments.Count
>End Function

>Public Sub Remove(intItem As Integer)
>    mcolAttachments.Remove intItem
>End Sub

>Public Function Item(intItem As Integer) As clsAttachment
>    Item = mcolAttachments.Item(intItem)
>End Function

>Private Sub Class_Terminate()
>    Set mcolAttachments = Nothing
>End Sub

>Public Function NewEnum() As IUnknown
>    Set NewEnum = mcolAttachments.[_NewEnum]
>End Function

>--- CLASS clsEmailer (the one that uses cAttachments)
>Public mAttachments As New clsAttachments

>Private Sub EncodeAttachments()
>    Dim cAttachment As clsAttachment

>    For Each cAttachment In mAttachments
>      ...
>    Next cAttachment
>End Sub
>.



Tue, 18 Oct 2005 05:05:06 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Cannot implement interface in VB with IUnknown retval

2. How to implement Interfaces with Propertys returning IUnknown????

3. How to implement Interfaces with Propertys returning IUnknown????

4. Exposing NEWENUM IUNKNOWN interface from a VBA Class mOdule

5. Implementing the IEnumerator interface in my custom class

6. Which classes implement an interface?

7. Need help Implement a class interface.

8. Identifying classes/components that implements certain interfaces

9. Implementing public interface of another class

10. Interfaces IUnknown

11. 'hidden' interface IUnknown

12. IMPLEMENTING AN INTERFACE MADE FROM ANOTHER INTERFACE

 

 
Powered by phpBB® Forum Software