Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2009
    Posts
    185

    Unanswered: Can I set a variable up in switchboard that is available to all forms.

    Can I set a variable up in switchboard that is available to all forms.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Simply declare it as Public in the declaration section of a standard module (i.e., not a Class module).

  3. #3
    Join Date
    Jul 2009
    Posts
    185
    That's simple but I am a newbeeee and what is a "standard module"

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    OK!

    In the main database window select Modules and click on the New button.
    A new windows opens: you are in a standard module. In this window type this code:

    Code:
    Public varSwitchBoard as Variant
    Click on the Save button (or select Save in the File menu) and when asked give the new module a name (e.g., "Mod_Declarations").

    Now you can use the varSwitchBoard variable from everywhere in your application, either for reading its value (x = varSwitchBoard) or for assigning a new value to it (varSwitchBoard = 45.2 or varSwitchBoard = "Hello world").

    To put it briefly, a module is said "standard" if it's not a class module (I know: not very helpful!). A class module is a module that is linked to a form or a report, or an independant module that has been defined as a class module when it was created. For more information search in Access help for "Modules".

    Have a nice day!

  5. #5
    Join Date
    Jul 2009
    Posts
    185
    I created a new module call main with
    Public sCurrentVersion as Variant
    that runs ok when I add
    sCurrentVersion="6.02" I get error
    I want all forms to be able to access sCurrentVersion

  6. #6
    Join Date
    May 2005
    Posts
    1,191
    Correct me if I'm wrong Sinndho, but don't you need to call at least one function on the module before the app recognizes it? I thought this was the case at least...

    Bob, to test this theory of mine, could you try the following:

    In the same module that Sinndho told you to create (go to your main window, modules, right-click it and go to design view), paste the following code below everything else in the module:
    Code:
    Public Sub RegisterPublicModule()
      on error resume next
      'register module
    End Sub
    Then go to the design view of your switchboard. Click the black box in the upper left-hand corner of your form, this will bring up the form's properties. Make sure you're in the "All" tab of the properties, then scroll down until you find the "On Open" event. Click inside that box, then click the button on the right-side of the box that has three dots inside it; this will cause a pop-up asking you what kind of Builder you want, select the "Code Builder" option. Then paste the following:
    Code:
    Private Sub Form_Open(Cancel As Integer)
      
      call RegisterPublicModule
      
    End Sub
    See if that helps. Cheers!

    My apologies if any of that came off as condescending, I don't know what level of "newbeeee" you're at.
    Me.Geek = True

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Nick,

    You don't have to call a function in a module to be able to use one of its public variable (you had me doubting for a moment, so I checked to be sure ). However you cannot directly reference a public variable as the RecordSource of a form's control nor in a query object. In both cases you have to use a public function that returns the value of the variable.

    Have a nice day!

Posting Permissions

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