Reputation: 1
I have a problem with changing all textboxes in a form with Null to a Value 0.0 after Lost Focus. Specifically, if the textbox is blank after pressing tab it would revert back to 0 since it affects calculations in the other part of the form. Writing the code for every textbox event procedure (57 or so boxes) seems tedious and the names for all the boxes are different.
I was wondering if there was an efficient way to go about changing the textbox value after losing focus easily rather than changing the event procedure for every textbox in the form.
Thanks
Upvotes: 0
Views: 91
Reputation: 2185
Figured I would give an example along with my comments. You could use something along these lines:
Public Function DefaultToZero(frm As Form)
Dim ctrl As Access.Control
For Each ctrl In frm
If ctrl.Tag = "Default" Then
If Nz(ctrl.Value, "") = "" Then
ctrl.Value= "0.0"
End If
End If
Next ctrl
End Function
Then you just select all controls while in design mode and set the tag to 'Default'. Not the best answer but I don't really see any other options besides using each "Lost Focus" event.
Upvotes: 0