![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm wanting to use a form bound to a table to restrict the possible value selections that will be assigned to the global variable. (Is that acceptable?) ..... |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Mike, David suggests using a form, which stays open throughout the session, to hold your variables instead of using global variables (which I'll show you how to set up in a moment). I think this is good advice - one thing I've learned from the more experienced folks here is that if you throw an error that is not trapped (ie, some kind of handling in your procedures' on error section), your global variables get reset, losing them and possibly messing up your app completely, requiring a restart. You could have an opening form (under the start up properties) in which you set your variables - give this a short name, because you'll be writing it a lot, I always use "frmV". The a click of a button on frmV to start the users off, instead of having a docmd.close for frmV, do the following: me.Visible = false 'Note this is on frmV itself. Which makes the form invisible. Any button or menu item anywhere else in which you want to make frmV visible again, use the code: Forms!frmV.Visible = True When you are developing, you can put a ' in front of the command making frmV invisible so that you can see that it is properly populating. To refer to the value in a control (I use mostly text boxes, but you can use other things - in fact, instead of using a table to limit values, one option could be to use combo boxes with value lists!) from another form, do it as follows (for the text box, txtTIMMY on frmV) in code or queries: forms!frmV.txtTIMMY With respect to global variables and how to set them: Go to your database window and select the "modules" tab. Create a new module and name it something - the name does not matter except as a means by which you can look at your list of standard modules and determine what is in them. "Standard" module refers to the modules in the modules tab of the database window. The modules that are directly associated with forms and reports are called "class" modules (I think - I stand to be corrected on that). Inside your new module, type: Public strGlbTest as String 'a test string Save the module and strGlbTestString is available to ALL forms, reports and other modules. Create a new form and call it "frmTest". In frmTest, create an unbound text box, txtGlobalValue, and a command button, btnGlobalValue. For the after update event of the text box write this: Private Sub txtGlobalValue_AfterUpdate strGlbTest = me.txtGlobalValue 'assigns what you type to strGlbTest End Sub For the on click event of the button write: Private Sub btnAdd_Click() msgbox strGlbTest 'message box with the new global variable value End Sub Have fun... 8) Note too, that in the standard module you can have subs and functions that can be called from anywhere in any module, form or report and even be used as a function in your Jet SQL! -- Tim - http://www.ucs.mun.ca/~tmarshal/ ^o /#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake /^^ "What's UP, Dittoooooo?" - Ditto |
![]() |
| Thread Tools | |
| Display Modes | |
| |