How to make an instance of an object available across multiple forms?

I want to make objects of a class that I'm working on accessable from all of my forms. I tried creating the object in a code module, but I couldn't use it from any of my forms. How can I go about doing this?

Comments

  • Hi,
    You have to declare a public variable like this:
    In a module type this in the default class:

    "Public strvariable as String"

    without the quotes. Then that variable will be visible in all forms. "strvariable" is the name of the variable so you can use any name there.

    HTH
    Dhruv(BattleGuard)


    : I want to make objects of a class that I'm working on accessable from all of my forms. I tried creating the object in a code module, but I couldn't use it from any of my forms. How can I go about doing this?
    :

  • I've tried this in a code module:

    Public DVD As New DVD()

    When I try to use properties and methods that I've created for the DVD class in any of my forms, I get this error:

    Reference to a non-shared member requires an object reference.

    What am I doing wrong?
  • Hi,

    I think the problem is that you're naming your variable the same name as the class. Try creating an instance of the DVD class by using a different name. For example,

    Public oDVD as New DVD()

    Hope this helps,

    Chris


    : I've tried this in a code module:
    :
    : Public DVD As New DVD()
    :
    : When I try to use properties and methods that I've created for the DVD class in any of my forms, I get this error:
    :
    : Reference to a non-shared member requires an object reference.
    :
    : What am I doing wrong?
    :

  • Hi,
    Maybe instead of using DVD() you should use String or Boolean or some of the more common type declarations.

    HTH
    Dhruv(BattleGuard)


    : Hi,
    :
    : I think the problem is that you're naming your variable the same name as the class. Try creating an instance of the DVD class by using a different name. For example,
    :
    : Public oDVD as New DVD()
    :
    : Hope this helps,
    :
    : Chris
    :
    :
    : : I've tried this in a code module:
    : :
    : : Public DVD As New DVD()
    : :
    : : When I try to use properties and methods that I've created for the DVD class in any of my forms, I get this error:
    : :
    : : Reference to a non-shared member requires an object reference.
    : :
    : : What am I doing wrong?
    : :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories