Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

dmon000 (TechnicalUser)
13 May 08 11:59
Hi Everyone,

I have a form which has several text boxes where users can enter criteria for queries that are executed by clicking on command buttons. I would like to add some code that would clear out the entries made upon clicking the command button, so that they could start over with an empty screen.

What would be the easiest way to do that?

THANKS!!
PWise (Programmer)
13 May 08 12:30
how about

CODE


me.undo
dmon000 (TechnicalUser)
13 May 08 13:15
Thanks but me.undo didn't work.
any other suggestions?
Helpful Member!  formerTexan (Programmer)
16 May 08 11:45

CODE

For Each Ctl In Me.Controls
  If Ctl.ControlType = acTextBox Then
    Me.Ctl.DefautValue = vbnullstring
  End If
Next Ctl
alternatively you can confine the loop to a section of the form: me.Detail.Controls

I also suggest you give the users a warning before their entries disappear.

Cheers, Bill
Helpful Member!  danvlas (Programmer)
16 May 08 12:00
This 'clears' everything:

On Error Resume Next
For Each Ctl In Me.Controls
    Me.Ctl = Null
Next Ctl
 

pipe
Daniel Vlas
Systems Consultant

http://www.geocities.com/danvlas/AutoMail.html

formerTexan (Programmer)
17 May 08 11:40
Sorry, but my earlier post should have read:

<code>
For Each Ctl In Me.Controls
  If Ctl.ControlType = acTextBox Then
    Me.Ctl.Value = vbnullstring
  End If
Next Ctl
</code>

There was a typo on the control (ctl) property.

Bill
dmon000 (TechnicalUser)
21 May 08 12:20
Thanks for your help, but VBA comes back and highlights the "ctl" in this line:
"Me.Ctl.Value = vbnullstring"
and says "not found".

What's missing?

Thanks?
RobertT687 (Programmer)
21 May 08 13:39
Dim Ctl as Control
danvlas (Programmer)
21 May 08 14:04
And lose Me.

ctl=Null (instead of Me.ctl)

vbNullString would insert "", which could create problems in number evaluation

pipe
Daniel Vlas
Systems Consultant

http://www.geocities.com/danvlas/AutoMail.html

bubba100 (TechnicalUser)
21 May 08 15:44
How about =""
dmon000 (TechnicalUser)
27 May 08 15:47
Thanks for the help. This is what I got to work:

Private Sub Command4_Click()
Dim Ctl As Control
For Each Ctl In Me.Controls
  If (Ctl.ControlType = acComboBox) Or (Ctl.ControlType = acTextBox) Then
    Ctl.Value = Null
  End If
Next Ctl
End Sub

THIS ALSO WORKS AND IS SIMPLER

Private Sub Command5_Click()
Dim Ctl As Control
On Error Resume Next
For Each Ctl In Me.Controls
    Ctl.Value = Null
Next Ctl
End Sub

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close