Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inputing form data into global variable?

Status
Not open for further replies.

chuq2001

Programmer
Jul 15, 2002
24
US
I want to read a value entered into a textbox of a form into a globaL VARIABLE. I don't know the vba code to do it in a module. Any help

Thank you
Chuck
 
In the textBox's AfterUpdate event procudure put

Private Sub TextBoxControlName_AfterUpdate()
GlobalVariableName = TextBoxControlName
End Sub


QED

G LS

 
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.


G LS
 
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.

Thanks
Chuck
 
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.
-----------------------
 
Here is what I got goin'

<code>Global vDiv1 As Variant</code>

<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 &quot;varTest2&quot;

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.
-----------------------
 
Thanks for all your help, I got the thing working(thank god)

godspeed
chuck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top