Form Field Triggers (1 Viewer)

GregoryWest

Registered User.
Local time
Today, 07:38
Joined
Apr 13, 2014
Messages
161
Here is an odd problem. Does a form element trigger get fired if the trigger is caused by another element?

Specifically, I have a field "Customer ID" I have a trigger "On Change" which causes a bunch of VBA code to executed. But I also what this code executed if the user click on the "Next Customer" button, or "Previous Customer" or any number of other buttons that do specific things, along with changing the customer number. The important thing is that the code be executed when ever the customer number is changed, no matter what caused it to be changed.
 

Minty

AWF VIP
Local time
Today, 12:38
Joined
Jul 26, 2013
Messages
10,354
No is the short answer. They are form events and VBA does not cause the form to fire any event.
You can however call / execute form events if they are made public.
 

GregoryWest

Registered User.
Local time
Today, 07:38
Joined
Apr 13, 2014
Messages
161
Was afraid of that. So basically I need to call a routine on almost every trigger of ever element on the form in question.... Not what I was hoping for.
 

MarkK

bit cruncher
Local time
Today, 05:38
Joined
Mar 17, 2004
Messages
8,178
when ever the customer number is changed, no matter what caused it
Are you familiar with the form's Current event? This event fires whenever the form loads a new record, which almost certainly occurs for Next customer and Previous customer.

A common pattern I encounter is that I write a FormReset procedure that updates the display of the user interface based on the data in the current record. This procedure is called by the form's Current event for sure, but also by other UI elements which change data, and where that data change might also change the appearance or functioning of the UI.

So let's say I load a new record with the Next Customer button. OK, I handle my Current event and call form reset . . .
Code:
Private Sub Form_Current()
   DoFormReset
End Sub
. . . but I also need to update the UI if I change the value of a particular control . . .
Code:
Private Sub txtSomeText_AfterUpdate()
   DoFormReset
End Sub
. . . and then I write one overarching UI reset routine that knows how to show the form correctly for all data (and maybe even make it public, so other objects might call it) . . .
Code:
Public DoFormReset()
[COLOR="Green"]'  Catch-all UI re-presentation routine based on current data[/COLOR]
   Me.txtSomeText.Enabled = Not IsNull(Me.txtSomeOtherText)
   Me.cmdSomeCommand.Enabled = Me.Dirty
   If Me.txtSomeNumbe > 6 Then 
      Me.txtSomeRelatedNumber = 22
   Else
      Me.txtSomeDate = Now()
   End If
End Sub
Makes sense? Don't do the work in the event handler. Rather, call the routine that does the work from the event handler.
 

Users who are viewing this thread

Top Bottom