Answered by:
Run VBA code when data is entered to any control on a form

Question
-
I am building a boundless form that has a button control for clearing the form. The button is disabled until there is actually data entered by the user. With a form bound to a table the process is simple. I use the Form_Dirty procedure. However, it looks like that only works with bound forms.
I thought about code in every control lostfocus event, but that's GOT to be the least efficient way to do it.
Any ideas?
tod
Friday, August 19, 2016 4:38 PM
Answers
-
I am building a boundless form that has a button control for clearing the form. The button is disabled until there is actually data entered by the user. With a form bound to a table the process is simple. I use the Form_Dirty procedure. However, it looks like that only works with bound forms.
I thought about code in every control lostfocus event, but that's GOT to be the least efficient way to do it.
Any ideas?
theDBGuy's idea of binding the form to a dummy table is clever, but you can also do it fairly simply by creating a common function procedure -- has to be a Function, not a Sub -- and then setting that as an expression in every control's AfterUpdate or Change event. For example, you could create this function procedure in the form's module:
Function EnableClearButton() Me.cmdClearForm.Enabled = True End Function
Then you could select all the editable controls on the form, open their joint property sheet, and set the OnChange property of all of them to:
=EnableClearButton()
That way, you don't have to have a separate event procedure for all those controls. Whenever any of them is changed by the user, the EnableClearButton() procedure will be called.
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html- Proposed as answer by Dziubek Michał Friday, August 19, 2016 10:26 PM
- Marked as answer by Deepak Saradkumar PanchalMicrosoft contingent staff Monday, August 29, 2016 6:52 AM
Friday, August 19, 2016 6:25 PM
All replies
-
Hi tod. Maybe you could bind the form to a dummy table. Just a thought...Friday, August 19, 2016 4:40 PM
-
I am building a boundless form that has a button control for clearing the form. The button is disabled until there is actually data entered by the user. With a form bound to a table the process is simple. I use the Form_Dirty procedure. However, it looks like that only works with bound forms.
I thought about code in every control lostfocus event, but that's GOT to be the least efficient way to do it.
Any ideas?
theDBGuy's idea of binding the form to a dummy table is clever, but you can also do it fairly simply by creating a common function procedure -- has to be a Function, not a Sub -- and then setting that as an expression in every control's AfterUpdate or Change event. For example, you could create this function procedure in the form's module:
Function EnableClearButton() Me.cmdClearForm.Enabled = True End Function
Then you could select all the editable controls on the form, open their joint property sheet, and set the OnChange property of all of them to:
=EnableClearButton()
That way, you don't have to have a separate event procedure for all those controls. Whenever any of them is changed by the user, the EnableClearButton() procedure will be called.
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html- Proposed as answer by Dziubek Michał Friday, August 19, 2016 10:26 PM
- Marked as answer by Deepak Saradkumar PanchalMicrosoft contingent staff Monday, August 29, 2016 6:52 AM
Friday, August 19, 2016 6:25 PM