And of course the declaration would be something like this.
Public g_GlobalVariableName As Variant ----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
Possibly "gClobalVariableName" if you want to get all Hungarian but then the event code will need to be changed to match it.
I was rather using GlobalVariableName as a pointer rather than as a string, but the need to flag GLOBAL variables as potentially dangerous things is well worth making.
The underscore is more a matter of preference and, I believe, used commonly in C++ development. I concur with you caution about using global variables. Besides the fact that there is not control over which functions may be changing the global they tend to reset values after an unhandled error. ----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
When I get the variable this way it gives me an error: Object doesn't support property of method. Basically, I have a form I would like to input the divisions of the company to query. I need to get those divisions from the form into a variable that my query can call. If I hard code the variable the query works, I just need to read in a string from a form into a variable. Should I use a Variant instead of a string? I'm stuck.
Could you be a little more specific. We speak code here. Paste a snippet into the window and you will get a response. Is the query a store query with a parameter, is is embedded SQL, what 'Object' is the error referring to that you are using.
----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
<code>Function Div1()
Div1 = vDiv1
End Function</code>
thats my variable and function
then I have a form with a text field, I want to input a value into the field, press a button(OK), and have the inputted value put in the variable, from there the query is run using the variable(actually I'll be running a report from that query)
button code
<code>Public Sub cmdSet_Click()
DoCmd.OpenQuery "varTest2"
End Sub</code>
<code>Private Sub Text1_AfterUpdate()
vDiv1 = txtDiv1
End Sub</code>
the problem is getting the value from the text field to the variable.
Can we assume the cmdSet_Click and the Text1_AfterUpdate are on different forms, otherwise there is no need for a global?
Observed that function Div1 does nothing. There is no need to have a function to return a global viable and also, I don't see it used anywhere in the following code.
Query 'varTest2' must be using parameter values which are supplied by the form controls.
The vDiv1 global variable should be assigned the value in the Control? called txtDev1. Comment, if you preface your control names with 'Me.' within the form class then Intellisense will prompt you with a list of the valid control names, otherwise you could type in an invalid control name. If you follow this guideline, Access will not be required to search and resolve the control during runtime, and it will speed up the processing.
If this doesn't help resolve your problem then use the debugger to verify the code. Merely place the cursor on the line to be checked and press (F9). Open the form and perform the update which should stop the processing at the breakpoint. Then take single steps of the code by pressing (F8). Inspect the values with Intellisense or by using the Immediate window.
----------------------
scking@arinc.com
Life is filled with lessons.
We are responsible for the
results of the quizzes.
-----------------------
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.