Assign Global Variable to TextBox Control Source (1 Viewer)

Lateral

Registered User.
Local time
Yesterday, 19:12
Joined
Aug 28, 2013
Messages
388
Hi Guys


Would somebody please look at answering my questions:


Ok, so here are my questions:


1. how do I specify a Global variable as the Control source for my text box either via VBA or direct?


2. Is if possible to directly set the Control Source of the text box to pick the PartName from the Active form???


Cheers
Greg
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:12
Joined
May 21, 2018
Messages
8,555
The first question is not correct. It is not a global variable, it is a public variable of a class module. So you want to know how to set a control source to a public variable of a class module. You likely have to show some code how you instantiate the class module and pass that to the form. So you need to ask the correct question to get the correct answer. The second question makes no sense, I have no idea what that is saying.
 

Lateral

Registered User.
Local time
Yesterday, 19:12
Joined
Aug 28, 2013
Messages
388
Hi Guys


Thanks for all of your replies....I really appreciate them.


based upon your comments, I have decided to change my approach and my logic to the

following:


1. When the user right clicks TextBox1, it now opens Form2 and passes it the PartID of the record of interest using the "Where" option



2. Form2 now has a data source that is a query containing the table that contains the data that it needs to be displayed such as PartName.


It now works great!


Thanks again for your help.


Cheers
Greg
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 21:12
Joined
Feb 28, 2001
Messages
27,263
Some people actually answered you original questions but it looks like you missed the answer.

1. how do I specify a Global variable as the Control source for my text box either via VBA or direct?

You cannot directly specify a public variable as a control source. There is no syntax for that. With VBA, however, you can put code in either the Form_Current or Form_Load event routine to assert the public variable into the value of the text box.

2. Is if possible to directly set the Control Source of the text box to pick the PartName from the Active form???

If this is on a bound form and you want to save the part name with the rest of the record, you don't want the .ControlSource anywhere other than pointing to the underlying record. Again, you might do something in the Form_Load or Form_Current routines.

You should also note that if you are running code on a form so that you can pick up something, then the form that is running IS the ActiveForm and therefore, the control from which you wanted to pick up something had better be on that form. The ONLY time this isn't true is if you have an open but hidden form running a timer in the background or if you have code running from a general module that was called from the active form.
 

Users who are viewing this thread

Top Bottom