[AccessD] Attach an afterupdate event handler to all text boxes on form

Anita Smith anita at ddisolutions.com.au
Thu Oct 31 18:16:36 CDT 2013


I'm not sure I get what it is you are trying to do here, but if all you want is to avoid having to go to every textbox's after update event in the code window then you could do the following;
1. Multi select all your text boxes
2. On the property sheet in the after update event enter =DataCheck()
3. Change your DataCheck procedure to a Function

Anita Smith


-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John Colby
Sent: Friday, 1 November 2013 10:04 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Attach an afterupdate event handler to all text boxes on form

Do it with a class?
On Oct 31, 2013 6:36 PM, "Doug Murphy" <dw-murphy at cox.net> wrote:

> Folks,
>
> This has probably been discussed in the event handling discussions of 
> past years but I can't find them. I have a data entry form with many text boxes.
> The form is used by folks in a lab to enter daily readings.  Each 
> reading has a set of parameters it is supposed to be within. If not a 
> dialog pops up so the person entering can add notes for the reading. 
> All this works well when I create an event handler for a given text 
> box and enter the call to DataCheck(). The routine the after update 
> handler calls gets the recordID, control name, parameters the values 
> is supposed to be between, and the value entered and performs the 
> comparisons and pops up the dialog if the value is out of bounds. I am 
> thinking I should be able to put some code in the form on load event 
> that would set all the text boxes after update events to my data check 
> routine. I created a routine to do this, see below, but when I test 
> the form I get a message "The expression After Update you entered as 
> the event property setting produced the following error: The object 
> doesn't contain the Automation object 'DataCheck".
>
> Any suggestions?
>
> Public Sub SetTextBoxProperties()
>     Dim ctl As Control
>    On Error GoTo SetTextBoxProperties_Error
>     For Each ctl In Me
>         If ctl.ControlType = acTextBox Then
>             ctl.AfterUpdate = "=DataCheck"
>         End If
>
>     Next
>
> SetTextBoxProperties_Exit:
>    On Error GoTo 0
>    Exit Sub
>
> SetTextBoxProperties_Error:
>
>     MsgBox "Error " & Err.Number & " (" & Err.Description & " at Line 
> Number = " & Erl & ") in procedure SetTextBoxProperties"
>     Resume SetTextBoxProperties_Exit:
>     Resume
> End Sub
>




More information about the AccessD mailing list