HELP PLEASE!!

N

Nick C

I have a command button in a data entry form that, when clicked, clears all
values except the date. Here is the code below:

Private Sub cmdClear_Click()

Dim c As Control

For Each c In Me.Controls
If (c.ControlType = acTextBox Or c.ControlType = acComboBox) Then
'Check to see if it is the date field
If (Not (c.Name = "txtDate")) Then
'clear contents
c.Value = Null
End If
End If
Next c
End Sub

I would like to duplicate this functionality in another form. However, the
other form has an AutoNumber Field and the Value property is not available.
When I try to use OldValue, I get an error stating (Object Required). I
have tried to set an object but have been unsuccessful in getting the code
to work thus far.

Any help at this point would be GREATLY appreciated. This has kept me up
the majority of the night.

Thanks very much in advance,

Nick
 
N

Nick

No, sorry. The clear fields function is meant to work before a recordset is
added. It's purpose is to allow users that have entered quite a bit of data
in a data entry form to clear it with one click and not have to highlight
EACH and every value then delete.

Nick
 
D

Dan Artuso

Hi,
Is this a bound form? If it is, clearing the values will actually delete them from the table.
More info on how your form functions is needed.
 
J

John Vinson

I have a command button in a data entry form that, when clicked, clears all
values except the date. Here is the code below:

Private Sub cmdClear_Click()

Dim c As Control

For Each c In Me.Controls
If (c.ControlType = acTextBox Or c.ControlType = acComboBox) Then
'Check to see if it is the date field
If (Not (c.Name = "txtDate")) Then
'clear contents
c.Value = Null
End If
End If
Next c
End Sub

If what you really want to do is wipe out all the user's work without
saving it to disk, and force them to start over, try this instead:

Dim dtOldDate As Date
dtOldDate = Me!txtDate
Me.Undo
Me!txtDate = dtOldDate
 
N

Nick

Dan, the form belonging to the command button and code listed is unbound.
The form that is giving me difficulty contains an Auto-Number field which is
bound.

Hope this explains things a bit better. I appreciate all the help.

Nick
 
R

Rick Brandt

Nick said:
Dan, the form belonging to the command button and code listed is unbound.
The form that is giving me difficulty contains an Auto-Number field which is
bound.

Hope this explains things a bit better. I appreciate all the help.

You cannot clear an AutoNumber, but you didn't address the issue raised.

Why would you want to clear all of the entries in a bound form? This is not the same
as deleting the record and it is not the same as moving to a new record so what
purpose does it serve?
 
N

Nick

I don't intend to clear the AutoNumber. And the reason the clear function
is useful is due to the fact that the data entry form is quite lengthy, and
users are requesting the functionality in case they want to clear the fields
and start over without entering a new record. Otherwise they have to enter
data over previously enterd values, or clear each field manually. The first
part is error-prone, and the second is quite lengthy. Basically, I would
like to duplicate the functionality of the unbound form and NOT clear the
AutoNumber field.

Can this be done?

Thanks,

Nick
 
H

Hugh O'Neill

Nick said:
No, sorry. The clear fields function is meant to work before a
recordset is added. It's purpose is to allow users that have entered
quite a bit of data in a data entry form to clear it with one click
and not have to highlight EACH and every value then delete.

Nick


Try:

Me.Undo

in the click event of your button.

hth

Hugh
 
R

Rick Brandt

Nick said:
I don't intend to clear the AutoNumber. And the reason the clear function
is useful is due to the fact that the data entry form is quite lengthy, and
users are requesting the functionality in case they want to clear the fields
and start over without entering a new record. Otherwise they have to enter
data over previously enterd values, or clear each field manually. The first
part is error-prone, and the second is quite lengthy. Basically, I would
like to duplicate the functionality of the unbound form and NOT clear the
AutoNumber field.

Can this be done?

Well whenever I want to perform an action on a bunch of controls on a form I give
them all a common tag property. Then I can loop through all controls and only
perform the action on those where the tag property contans that value. This avoids
all of the issues where you otherwise have to test for the type of control or the
DataType of its bound field etc..

EX:

Dim Cnt as Control

For Each Cnt in Me
If Cnt.Tag = "Clear" Then Cnt = Null
Next Cnt
 
N

Nick

Rick, thanks for your help! I should have thought of that, I bet it will
work just fine.

Nick
 

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

Similar Threads


Top