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

Form (global) level event handling 1

Status
Not open for further replies.

flize

IS-IT--Management
Jun 23, 2003
14
0
0
US
I have a form with a lot of editable text boxes. When the user changes (updates) the data in some of the text boxes, I want to set a global boolean variable to true. However, I don't want to create an after_update event procedure for each and every text box just to set one global variable to true.

Is there a way to trap events from controls at the form level versus at the individual control level, so I don't have to create a lot of individual event procedures that all do exactly the same thing (update the same variable)?

I want to create a 'global' event at the form level to just trap all 'after_update' events from all the control objects on the form. And then execute one line of code if the control is a textbox and meets certain criteria like the control name starts with "txt". That is necessary to consider because there are some other editable text boxes on the form that should never set the global variable = true even though they would trigger this 'global' after_update event.

thanks,
flize
 
Provided the form is bounded to a Table/Query you may consider playing with the Dirty property of the form and the OldValue property of the controls, in the BeforeUpdate event procedure of the form.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV, the form is unbound. The text boxes get their values from code written in a subform. As the user scrolls through records on a grid on the main form (via a subform datasheet), the subform's form_current event writes current record field values back to the main form text boxes.
Then, if the user edits any data in the main form text boxes and doesn't hit a 'save' button, they should be prompted to do so.
 
you could dynamically assign a function call to the afterupdate event of each textbox. Something like:
Code:
Private Sub Form_Load()
  Dim ctl As Control
  
  For Each ctl In Me.Controls
    If TypeOf ctl Is TextBox Then
      If Left(ctl.Name, 3) = "txt" Then
        ctl.AfterUpdate = "=MakeDirty()"
      End If
    End If
  Next
End Sub

Private Function MakeDirty()
  MsgBox "dirty"
End Function
Cheers,
Dan
 
DanJR,
Excellent - a star for you! That answered my question.

Thanks much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top