Clearing textboxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmrhema
    Contributor
    • Jan 2007
    • 375

    #1

    Clearing textboxes

    This is reference to Vandana Sridhar's refreshing the form

    The code displayed below did work.

    Code:
    Dim Ctrl As Control
       For Each Ctrl In Me.Controls
       If TypeOf Ctrl Is TextBox Then Ctrl.Text = ""
       Next
    But I have three frames inside the form
    Each of the frames consist of 15 text boxes. If I click Add button then the frame1 is visible, By clicking Modify btn frame2 is visible and so on.
    Inside each frame I have two btns cmdsave and cmdcancel.
    What I want is by clicking on cmdcancel I want the textboxes of that particular frame only cleared.
    eg. By clicking on cmdcancel I want textboxes of frame1 to be cleared
    not the other two frames
    Where should I modify
    I tried
    For Each Ctrl In Frame1
    But it resulted in an error

    Help appreciated
    Thanks
  • vijaydiwakar
    Contributor
    • Feb 2007
    • 579

    #2
    Originally posted by cmrhema
    This is reference to Vandana Sridhar's refreshing the form

    The code displayed below did work.

    Code:
    Dim Ctrl As Control
       For Each Ctrl In Me.Controls
       If TypeOf Ctrl Is TextBox Then Ctrl.Text = ""
       Next
    But I have three frames inside the form
    Each of the frames consist of 15 text boxes. If I click Add button then the frame1 is visible, By clicking Modify btn frame2 is visible and so on.
    Inside each frame I have two btns cmdsave and cmdcancel.
    What I want is by clicking on cmdcancel I want the textboxes of that particular frame only cleared.
    eg. By clicking on cmdcancel I want textboxes of frame1 to be cleared
    not the other two frames
    Where should I modify
    I tried
    For Each Ctrl In Frame1
    But it resulted in an error

    Help appreciated
    Thanks
    See the text boxses are not the child of frame so it will results an error

    Comment

    • vijaydiwakar
      Contributor
      • Feb 2007
      • 579

      #3
      try this code
      Code:
      Private Sub Command1_Click()
          Dim ctrl As Control
          For Each ctrl In Me
              If TypeOf ctrl Is TextBox Then
                  If ctrl.Container Is Frame1 Then
                      ctrl.Text = ""
                  End If
                  
              End If
          Next
      End Sub
      
      Private Sub Form_Load()
          Text1.Container = Frame1
          Text2.Container = Frame1
      End Sub
      to test this put three text boxses , 1 frame and one cmd button
      2 in frame and last on form
      click button it will clear the text boxes in frame1 only

      Try it
      Good Luck

      Comment

      • cmrhema
        Contributor
        • Jan 2007
        • 375

        #4
        Thnx. your code worked
        I tried by placing text1 on frame1 and text2 on the form (not inside the frame) and i commented the line
        ' Text2.Container = Frame1

        The result only text1 got cleared but text2 remained as it was.
        One more doubt if i place 10 textboxes on frame1 then am i supposed to write for eachboxes
        text1.Container =Frame1
        text2.Container =Frame1 till text10

        Comment

        Working...