How do I clear a form field once data was entered into the record?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We have a variety of text fields that are completed for every record. When we
create the new record, the text from the previous entry is still there - we
have to go back and clear all text fields to make sure data from the previous
record is not in the new record. How do I get it to add the text to the
record when entered but then clear the text box for the next record?
 
There is something very strange here. How do you create a new record?
Normally, when you add a record in a form, all the controls become Null.
In fact, it would be interesting to see what you are doing, because at least
once a week, there is a post from someone asking how they can preserve the
values from the previous record when they add a new one.
 
We have a variety of text fields that are completed for every record. When we
create the new record, the text from the previous entry is still there - we
have to go back and clear all text fields to make sure data from the previous
record is not in the new record. How do I get it to add the text to the
record when entered but then clear the text box for the next record?

This is done automatically if the controls on the form are bound to a
field in a table.
If you are using unbound controls, then you'll need to code the
Current event of the form, something like this:

Dim C As Control
For Each C In Me.Detail.Controls
If TypeOf C Is TextBox Then
If C.ControlSource = "" Then
C.Value = Null
End If
End If
Next

Add error handling and other control types as needed.
 
I have the same issue. My fields are bound on my form. Per the bossman, I need to just write over the data in three fields becuase we do not need to keep history of this particular data. So I need a button to clear my fields to 0 and make my date field todays date. I do not want to use onload. I want to click a button and have it happen. My VB says this currently:

Private Sub CLEARcmd_Click()
Me.dateCMD = Date
Me.rcvdTXT = 0
Me.ShortTXT = 0
End Sub

But when I click the button, it does nothing.
 
Then I put:

Private Sub CLEARcmd_Click()
Me.dateCMD.Value = Date
Me.rcvdTXT.Value = 0
Me.ShortTXT.Value = 0
End Sub

Basically I put .Value after each one and clicking the button still did nothing. (button still down change my data)

SideNote:
Don't pay any attention to the fact that I named my textbox with the clue of CMD for the dateCMD (it is really a text field).
 
Last edited:
Back
Top