icemonster
Registered User.
- Local time
- Today, 11:48
- Joined
- Jan 30, 2010
- Messages
- 502
how do you loop the onchange event?
sample
for each control
onchange = subroutine
next
sample
for each control
onchange = subroutine
next
Dim ctl As Control
For Each ctl In Me.Controls 'Or some other controls collection
ctl.OnChange = "Macro1" 'for example
Next ctl
Dim ctl As Control
For Each ctl In Me.Controls 'Or some other controls collection
If ctl.ControlType = acTextBox Then ctl.OnChange = "Macro1" 'for example
Next ctl
how bout combo boxes?
and where would this code be placed?
Sub Test()
Command1.OnClick = "TestFunc"
End Sub
Function TestFunc()
MsgBox "Test"
End Sub
Sub Test()
Command1.OnClick = "=TestFunc()"
End Sub
Function TestFunc()
MsgBox "Test"
End Sub
Private Sub Form_Open(Cancel As Integer)
Command1.OnClick = "=TestFunc()"
End Sub
Function TestFunc()
MsgBox "Test"
End Function
Option Explicit
Option Compare Text
Private intChangeEventHasFired As Integer
Private Sub Form_Open(ByRef intCancel As Integer)
Dim ctl As Control
[color=green]' Not all controls have a change event.[/color]
On Error Resume Next
For Each ctl In Me
ctl.OnChange = "=HandleChangeEvent()"
Next ctl
End Sub
Private Function HandleChangeEvent()
intChangeEventHasFired = True
End Function
Private Sub Form_Unload(ByRef intCancel As Integer)
[color=green]' Note that if an Application.Quit or DoCmd.Quit
' command has been executed anywhere in the project
' then the intChangeEventHasFired Flag will be
' set to False before this event is fired.[/color]
If (intChangeEventHasFired) Then
[color=green]' Do whatever needs doing.[/color]
End If
End Sub