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:
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".
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:
Public Sub RegisterPublicModule()
on error resume next
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:
Private Sub Form_Open(Cancel As Integer)
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.
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.