Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002
    Posts
    19

    Unanswered: Variable Declaration

    I am setting up a module to move all of my supporting code to (from my form). I am seeing something strange. First off, I am wanting to create some globa variables in this module to use throughout. These include the following variables:

    frm as form
    lb_MkSg as Control
    lb_SoldTo as Control


    I have these in the General Declarations of my module.

    Also, I set the value for the variables using the following text:

    Set frm = Forms("FormName")
    Set lb_mksg = frm("lb_mksg")
    Set lb_SoldTo = frm("lb_SoldTo")

    The two controls are listboxes with the respective names. Now I am having problems accessing these controls through my code. In my Subs in my module, when I type in the control such as lb_mksg to access my items within the control (ie. lb_mksg.column), I get none of the elements for this control. Have I decalred the variables properly? Funny thing is, within my sub, I can attempt to re-establish the reference to the control using the same code and I get the same response; however, if I remove the instance of this control from my Declarations section, my reference in the Sub will then work. The problem with this, won't I have to then declare these variables in each of the subs I that I would like to use them in? I would prefer to declare them once and that be it.

    Thanks

  2. #2
    Join Date
    Jul 2002
    Location
    Romania
    Posts
    122
    You have to use either Public or Global in declaring the variables:

    Public frm as form
    Public lb_MkSg as Control
    Public lb_SoldTo as Control

    It should work, but be sure to set them to Nothing after you use them, otherwise they will not release stack/memory after running your code.
    Keep in mind that:

    Set frm = Forms("FormName")
    works only if the form is open. Otherwise, you'll get a run-time error.

  3. #3
    Join Date
    May 2002
    Posts
    19

    Problem found...I Believe

    I belive that the problem that I am having is using the SET command in my General Declaration. I belive that this command can only be used in my Subs. Is this correct?

    Thanks

  4. #4
    Join Date
    Jul 2002
    Location
    Romania
    Posts
    122
    Absolutely!

Posting Permissions

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