PDA

Click to See Complete Forum and Search --> : Clear out the controls in a Form


ChrisJackson
Jan 12th, 2000, 10:45 PM
Hi.

My program has two Forms. Choosing an option on Form1 brings up Form2. When I go to the second Form, enter some data and click "Cancel", I go back to the first Form with "Me.Hide" and "Form1.Show".

However, when I go Form2 again, all of the values that were entered previously are still there. I want the controls to reset to their default value when I click "Cancel" on Form2. In other words, I want the controls to have the values that they would have if I was opening the Form for the first time.

I know that I can reset the value for each control individually upon clicking "Cancel", but I was wondering if there was an easier way to do this. Any suggestions?

Thanks.

Chris

netSurfer
Jan 12th, 2000, 10:56 PM
I would throw into a Clear function code to reset each control

id:

txtText1.text = ""
txtText2.text = ""

something like that and then call that function either when you click the cancel button or whenever you goto the form

[This message has been edited by netSurfer (edited 01-13-2000).]

Aaron Young
Jan 13th, 2000, 11:02 AM
Why don't you just unload Form2, then when you reload it the values will be Reset.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

WadeD
Jan 13th, 2000, 11:04 AM
This isn't the exact syntax, but isn't there a generic way to enumerate the controls like:

For Each Control In Controls
If Control Is TextBox Then
Control.Text = ""
End If
Next



Regards,
Wade

ChrisJackson
Jan 13th, 2000, 11:11 AM
Thanks netSurfer, Aaron and WadeD.

Of the 3 options you all provided, Aaron's was the easiest to implement (and the one that I was looking for actually).

I know that this was a simple one but I'm sick and the ol' brain isn't working so well right now (e.g., I tried to do a Me.Unload rather than Unload Me before starting this thread!). I'm feeling a little lazy too.... ;).

Thanks again,

Chris