Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Brugge, Belgium
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    The scope of a variable (MS Access2007)

    I like to use a variable in my form "frmOrders" as well as in my subform "sfrmOrders".
    As I believe to have understood the scope of a variable, when I declare the variable in the declaration section of my formmodule of "frmOrders", i can't see this variable in my subform and therefore I need to have a global variable in order to make this possible.
    My question now is the following one, Does there exists another way than using a global variable to give a variable a scope that range over more than one formmodule, or is the only solution to full qualify the variable in the other form e.g. variable in frmOrders : OrderItemDeleted As Booleaan and in SubfrmOrders : If Me.Parent!OrderItemDeleted then ... .

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: The scope of a variable (MS Access2007)

    You can declare the variable as Public in the code module of frmOrders:

    Public OrderITemDeleted As Boolean

    You can then refer to the value of this variable anywhere as

    Form_frmOrders.OrderItemDeleted

    And from the subform sfrmOrders you can refer to it as

    Me.Parent.OrderItemDeleted

    Another possibility is to store a value in a hidden control (in this example a check box) named OrderItemDeleted. You can then refer to it as

    Forms!frmOrders!OrderItemDeleted

    or from the subform

    Me.Parent!OrderItemDeleted

    Yet another possibility is to declare the variable as public in a standard module (the type of module that you create in the Modules section of the database window):

    Public OrderITemDeleted As Boolean

    You can then refer to it anywhere in the code in your database as

    OrderItemDeleted

Posting Permissions

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