Clear Data...

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hello is there a way I can clear all the data on a form?
So for example if there was data in combo boxes and text
boxes is there a way to clear them all and start again...
Something like a new record but just clears teh screen of
data in effect?

Thanks

James
 
Hello is there a way I can clear all the data on a form?
So for example if there was data in combo boxes and text
boxes is there a way to clear them all and start again...
Something like a new record but just clears teh screen of
data in effect?

Thanks

James

Put a line in the VBA of some suitable event (the Click event of a
"CLEAR" button for instance):

Me.Undo
 
James said:
Hello is there a way I can clear all the data on a form?
So for example if there was data in combo boxes and text
boxes is there a way to clear them all and start again...
Something like a new record but just clears teh screen of
data in effect?

Just to expand a little on what others have said, the line of code

Me.Undo

will undo all changes to bound controls that have been made since the
record was last saved. It won't clear unbound controls, and it won't
clear a field to Null or blank if it wasn't empty before the user began
editing it. If you want to do that, you have to loop through the
controls and explicitly set each one's value to Null.
 
Hello there...

I was wondering how I clear unbound controls as well and
just like wipe all the data from the whole form?

wipe = Clear

Thanks

James
 
James,

As Dirk suggests, loop through the controls and set them
explicitly to Null. As I assume you would want to
preserve labels, lines, and other controls that do not
receive user input, test the control type before setting
it to Null. The following code sets all combo boxes, text
boxes, option groups, and list boxes to Null:

Private Sub cmdClearSelection_Click()
' Reset all controls to Null
For Each ctl In Me.Controls
If (ctl.ControlType = acComboBox Or _
ctl.ControlType = acTextBox Or _
ctl.ControlType = acOptionGroup Or _
ctl.ControlType = acListBox) Then
ctl.Value = Null
End If
Next ctl
End Sub

HTH
Kevin Sprinkel
 
Thanks for that... Works a treat...

James :)
-----Original Message-----
James,

As Dirk suggests, loop through the controls and set them
explicitly to Null. As I assume you would want to
preserve labels, lines, and other controls that do not
receive user input, test the control type before setting
it to Null. The following code sets all combo boxes, text
boxes, option groups, and list boxes to Null:

Private Sub cmdClearSelection_Click()
' Reset all controls to Null
For Each ctl In Me.Controls
If (ctl.ControlType = acComboBox Or _
ctl.ControlType = acTextBox Or _
ctl.ControlType = acOptionGroup Or _
ctl.ControlType = acListBox) Then
ctl.Value = Null
End If
Next ctl
End Sub

HTH
Kevin Sprinkel



.
 
Back
Top