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 Forums!
  • 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.

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.

CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

(OP)
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!!

RE: CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

how about

CODE


me.undo

RE: CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

(OP)
Thanks but me.undo didn't work.
any other suggestions?

RE: CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

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

RE: CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

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

RE: CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

(OP)
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?

RE: CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

Dim Ctl as Control

RE: CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

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

RE: CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

How about =""

RE: CLEAR FORM OF ENTRIES WITH COMMAND BUTTON

(OP)
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