Results 1 to 5 of 5

Thread: Clear out the controls in a Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    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

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    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).]

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Why don't you just unload Form2, then when you reload it the values will be Reset.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  4. #4
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    This isn't the exact syntax, but isn't there a generic way to enumerate the controls like:
    Code:
    For Each Control In Controls
       If Control Is TextBox Then
          Control.Text = ""
       End If
    Next
    Regards,
    Wade

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width