Originally posted by mmccarthy
Help in clearing form data!!!
Collapse
X
-
Hi again
So! I haven't yet receved my book so mean while I'm still stuck knowing a little less than nothing about VBA programming.
Could there be anything done about the code giving an error when there are controlled objects on the form. For the moment I have a textbox that gets data depending of values from other controls. For example just ignoring those objects.
Thanks in advanceComment
-
I've changed the original code somewhat. Considering this is a function to clear unbound controls, it's only right that there should be a check to see if the control is unbound ;)
See if this works better for you.
Code:'ClearUnbound empties all controls on an unbound form. Public Sub ClearUnbound(frmMe As Form) Dim varCtrl As Variant For Each varCtrl In frmMe.Controls With varCtrl Select Case .ControlType Case acCheckBox, acComboBox, acListBox, acTextBox If IsNull(.ControlSource) Then .Value = Null End Select End With Next varCtrl End SubComment
-
Sorry. I expect the check of (.ControlSource ) should be for an empty string rather than Null. Try this amended version :
Code:'ClearUnbound empties all controls on an unbound form. Public Sub ClearUnbound(frmMe As Form) Dim varCtrl As Variant For Each varCtrl In frmMe.Controls With varCtrl Select Case .ControlType Case acCheckBox, acComboBox, acListBox, acTextBox If .ControlSource = "" Then .Value = Null End Select End With Next varCtrl End SubComment
Comment