Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005

    Unanswered: global variable issue

    I am creating a global variable using vba and I am not able to access it when I open a new form. Here is my code:

    Option Compare Database
    Public intDistrict As Integer
    Option Explicit
    form 1...

    Public Sub Command6_Click()

    intDistrict = 1

    End Sub

    form 2........

    Private Sub Form_Load()

    MsgBox (intDistrict)

    End Sub

    I used a msgbox to test the variable at the end of form 1 and the variable is in fact holding the value. When I get to page 2 the value does no longer does not populate the variable. Thanks for the help.

  2. #2
    Join Date
    Mar 2003
    The Bottom of The Barrel
    Provided Answers: 1
    Try declaring it as global instead.

    In all truth, all of your global variables should be in a module...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Jun 2003
    I don't usually try to use true global variables because after an untrapped error all the global variables lose their values.

    My Access apps often have a main menu form that stays open all the time. Other forms get opened in front of it and most of the time you can't even see the main menu, but it's still an open form. So what I do in the few cases where I need a global value is to simply put in on the main menu (and the text box it goes in would be invisible usually).
    J. Paul Schmidt, Freelance Web and Database Developer
    Access Database Sample, Web Database Sample, ASP Design Tips

Posting Permissions

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