Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing the contents of a field on a form

Status
Not open for further replies.

HockeyFan

MIS
Jun 21, 2005
138
US
Access 2003.
On a form, I would like to click a button, i want it to clear the contents of almost all of the fields on the form. Since I don't want it to clear all of the field, I will need a command that I can specify which fields to clear the contents from.
I couldn't find a function or command to do this and I don't know if it will have to be in vba or not? Please help.
 
I know of no way other than vba. Try something like this.

For the text boxes you want to clear, set the Tag property to "Clear". Then, add this code to the click event of your button.

Code:
Private Sub cmdYourButton_Click()
    Dim ctl As Control
    For Each ctl In Me
        If ctl.Tag = "Clear" Then
            ctl.Value = ""
        End If
    Next ctl
End Sub

Randy
 
thanks.

i think i'm gonna go with this though Me.TextboxName = "".
thanks again
 




"i think i'm gonna go with this though Me.TextboxName = "".


?????????

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
why the question marks? i was able to accomplish the same thing with 1 line of code.
i do appreciate your help though.
 
i was able to accomplish the same thing with 1 line of code
It seems to me you can only clear ONE textbox with this ONE line of code. You will need the same line for EACH textbox you want to clear.

Your original post stated that you want to clear almost ALL of the fields. With your method, if ALL amounts to more than 6, you've used more lines of code than I provided.


Randy
 


"i want it to clear the contents of almost all of the fields on the form."

"i was able to accomplish the same thing with 1 line of code."

So you're saying that this one line...
Code:
Me.TextboxName = ""
clears almost all of the fields on the form?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
How are ya HockeyFan . . .

For all others (including myself) following this thread, could post the final code or routine you used!

I'm not sure if you simply used the one liner multiple times or alone! [surprise}

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Hi Randy,
I'm gonna try your code to use on my form! On form load, I created a function to clear every single control (me.ctrlname = "") but based on what you're saying I don't have to so thanks!!
Annie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top