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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Databound control

Status
Not open for further replies.

MasterRacker

New member
Oct 13, 1999
3,343
US
Let's say I have a form with a textbox on it and an unrelated module that has a public variable declared in it. The variable is a counter and I would like to display it as it changes. I could update the status bar but I would like to do it on the form without the module knowing anything about any specific form or control.

Is there a way to bind a control a variable so it would update as the variable changes? I created a one line function that returns the counter and set the textbox data source to the function ( =DisplayCount() ) This display the initial value of the variable but does not update when the variable changes.

I'm thinking I have to create a event handler based on the change of the counter and pick it up in the form somehow, but at this point I'm clueless (at least trying to do this in VBA.)

_____
Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
You may requery the textbox in which event you want.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
As you've suggested, you could re-assign the value of the global variable to the textbox with code each time the count changes. What kind of event triggers the increase in the variable?

You could also place your function that does this in the Form_Timer event. In the form's Property Sheet set the Timer Interval in increments of 1000 for each second you want between re-polling of the variable.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Solution 1
Make a subroutine that is used for changing the variable (a parameter is passed with a positive or negative number that is the modifier). From there, call DisplayCount.

Solution 2
Create a small class with a Single "Counter" property. Declare a "CountChanged" event in it that is raised when the Counter property is changed.
Replace your variable with an instance of this class, make sure to declare it "With Events", and in the CountChanged event call DisplayCount.


Joe Schwarz
Custom Software Developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top