Clear Data...

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
 
J

John Vinson

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
 
D

Dirk Goldgar

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.
 
J

James

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
 
K

Kevin Sprinkel

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
 
J

james

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



.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top