Doug Murphy
dw-murphy at cox.net
Sun Feb 2 12:38:14 CST 2014
I do something similar to this on a form with a similar number of text entry boxes. I call a routine from load that is as follows; For Each ctl In Me If ctl.ControlType = acTextBox Then If ctl.Tag <> "False" Then ctl.AfterUpdate = "=DataCheck()" End If End If Next Certain text boxes don't require the check so I use the control tag to designate this. Works well and is simple. Doug -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Salakhetdinov Shamil Sent: Sunday, February 02, 2014 9:07 AM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Multiple Unbound Text Boxes After Update Event Hi Vlad, As Jim noted WithEvents would be an overkill - just use code behind: Private Sub Form_Load() Dim ectl As Object For Each ectl In Me.Controls If ectl.ControlType = 109 Then ectl.AfterUpdate = "=TextBox_AfterUpdate()" End If Next ectl End Sub and standard module function Public Function TextBox_AfterUpdate() Dim txt As TextBox Set txt = Application.Screen.ActiveControl Debug.Print "After update [" & txt.Name & "] = " & _ "'" & txt.Value & "'" End Function or instead of code behind you can use a function from a standard module to set AfterUpdate event processing function for TextBox controls of a form, which instance object reference is passed in parameter: Public Sub SetAfterUpdateHandler(ByRef frm As Form) Dim ectl As Object For Each ectl In frm.Controls If ectl.ControlType = 109 Then ectl.AfterUpdate = "=TextBox_AfterUpdate([Form])" End If Next ectl End Sub Public Function TextBox_AfterUpdate(ByRef frm As Form) Dim txt As TextBox Set txt = frm.ActiveControl Debug.Print "After update [" & txt.Name & "] = " & _ "'" & txt.Value & "'" End Function > There are other text boxes and combo boxes on this form, but I don't > want the code to apply to them. Is this possible? Just skip them while you're setting AfterUpdate event handler - as JC noted - use a naming convention or .Tag property with special values for the controls to be skipped or to have their AfterUpdate event handler set. -- Shamil Sunday, February 2, 2014 10:35 AM -05:00 from John W Colby <jwcolby at gmail.com>: >Or use a class and a control scanner. Then use a naming convention such >that each control that needs this stuff done has some common text in the name. > >John W. Colby > >Reality is what refuses to go away >when you do not believe in it > >On 2/2/2014 10:15 AM, Jim Dettman wrote: >> As Shamil mentioned, you can with a text box class and with events, >> but it's a lot of work to hook it up. >> >> What you can also do is write one procedure that accepts a form and >> control reference as string arguments, and then with some code set >> all the afterupdate events in the property sheet to that procedure. >> >> I can dig out an example if you want. >> >> Jim. >> -----Original Message----- >> From: accessd-bounces at databaseadvisors.com >> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of ACTEBS >> Sent: Sunday, February 02, 2014 07:14 AM >> To: accessd at databaseadvisors.com >> Subject: [AccessD] Multiple Unbound Text Boxes After Update Event >> >> Hi Everyone, >> >> >> >> I have a form that has a sections with 100 separate text boxes that >> require users input. Once the user inputs values it triggers various >> calculations to be carried out. >> >> >> >> My question is, instead of having an After Update event triggered for >> each text box, which is a lot of code to manage, is it possible to >> execute the code in some other fashion that applies to these 100 text >> boxes only, but can be placed in one module? >> >> >> >> There are other text boxes and combo boxes on this form, but I don't >> want the code to apply to them. Is this possible? >> >> >> >> Thanks >> >> >> >> Vlad >> > -- Салахетдинов Шамиль -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com