• Trouble with object reference (VBA – Word 2000)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Trouble with object reference (VBA – Word 2000)

    Author
    Topic
    #358869

    We use an object reference in VBA code for Word 97 and it works fine. Now converting to Word 2000 and unable to figure out why it generates run-time error.

    Under Word 97
    dim oAuthorsQ as object
    dim members as object

    set members = new clsautharr

    set oAuthorsQ = createobject(“mlis_authors.member_query”)
    oAuthorsQ.Membership members

    the code above works fine under 97
    (returning array of names from Foxpro table)

    but under 2000 generates error on execution of last line of code as follows:
    Run-time error 98.
    A property or method cannot include a reference to a private object, either as an argument or as a return value.

    Under the class module property window, the instancing property is private and only other option is PublicNotCreateable.

    I tried to declare the objects as public before instead of dimming in private module, but that didn’t work either.

    Thanks.
    Ann Brandon

    Viewing 0 reply threads
    Author
    Replies
    • #536454

      It generates a runtime error because you have apparently declared clsautharr as a user-defined class object and you’re assigning it to an object variable and then trying to pass that object to the oAuthorsQ.Membership method. The message is telling you that you can’t do that.

      VB/VBA 6 seems to be different in a number of ways from 5, and I think you’re running into one of them. If you open the class module in WordPad, you’ll see attributes that you may not be able to set from within the VB editor. Here’s an example:

      Attribute VB_Name = “clsCapAcct”
      Attribute VB_GlobalNameSpace = False
      Attribute VB_Creatable = False
      Attribute VB_PredeclaredId = True
      Attribute VB_Exposed = False

      In Access, changing the Exposed property to True allows you to use the class from a library database. If you change Creatable to True, you can declare an object as an instance of that class. I haven’t tried this with VB 6 or Word, but it’s worth a try.

      • #536557

        Hi Charlotte,
        I changed the instancing property in the VB Editor from private to publicnotcreatable and that changed the attribute vb_creatable to false and the attribute vb_exposed to true.

        That did the trick!

        The instancing property was not included in the properties window under VB5, but it is included under VB6.

        You’re great!

        • #536568

          Glad it worked. I can never remember exactly what the individual attributes in the class module are for, but I manage to remember which one I need to tweak to expose them. shrug

    Viewing 0 reply threads
    Reply To: Trouble with object reference (VBA – Word 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: