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!

Is there a better way?

Status
Not open for further replies.

combs

Programmer
Apr 18, 2002
78
US
I have several (25) textboxes on a form. I would like to write code that will fire on an AfterUpdate event. (i.e. when a value changes in the text box and the user moves focus to another text box).

Is there a way besides writting 25 seperate subs to do this for all 25 text boxes? I have copied the code from a single text box below:

Code:
Private Sub QTD1_AfterUpdate()
    MsgBox "AfterUpdate Event..."
End Sub

All the text boxes follow the same naming scheme from QTD1 to QTD25. Also, there are several columns (8) of the 25 text boxes on this form (all are uniquely named).

Any help or suggestions would be greatly appreciated.
 
Do a search in this forum for control arrays, then if you need further help let us know.

Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
You can also do a For Next on the form Controls collection and compare the name of each control object

Dim myControl as Control

For Each myControl in Controls
if myControl.name = "somename" then
DoSomething
end if
Next myControl

 
He'd still be left with having to write 25 seperate event procedures though.

DrJavaJoe has the right solution.
 
To avoid using a control array and still want to use Centerfuge's solution,

Dim myControl as Control

For Each myControl in Controls
If TypeOf myControl Is TextBox Then
DoSomething
end if
Next myControl


------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
How does that avoid the necessity of having 25 seperate event procedures? Said event procedures may be no more than a stub for calling a centralised routine, but they still need to exist.
 
It's been awhile since I've worked with VB, I'm doing C# now, but I seem to recall wiring up the event procedures within the loop as well when they were fairly similar. I could be attributing that to some C# code though. It's been too long.
 
Strongm is correct. If you are not using a control array, you will need 25 seperate events to fire the function.

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Since when is there an AfterUpdate event on the VB textbox? It would seem that combs is using Access. Can you even have control arrays in Access? I don't know that much about Access.
 
I thought that was perhaps because he just hadn't looked up the correct event name. In VB, I would suggest the Validate Event.

If you are in Access though, good luck to you...

mmilan
 
to vbsun,

The correct termininology is called PEBKAC which stands for:
Problem exists between keyboard and chair.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top