Results 1 to 5 of 5

Thread: Can I make a procedure|function to clean textbox on selected forms?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Can I make a procedure|function to clean textbox on selected forms?

    So, I already know how to do it locally using a 'For each' loop.
    I also know how to do it from a code module, but for some reason (I'm just beginning to learn, go easy on me folks ) I can just make it work for the first form in my project.

    The code in the code module looks like this (I'm not sure, I'm not at home right now)


    public function RF(cleanctls as control) as control

    for each typeof cleanctls in form1
    if cleanctls = textbox then
    cleanctls = ""
    next

    ... and then the Textboxes in form1 go empty. What I'd like to know(even though it's short enough to be a local procedure, but for us programmers that just isn't enough right? Or I should say you since I'm just learning here)

    is how to make it work for more forms in case I'm so lazy as to not want to type all that again in a local procedure or function to clean texboxes in a form. So, what's the way, dear elders? =0

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Can I make a procedure|function to clean textbox on selected forms?

    Welcome to VBForums

    Your code has a few issues, but I get the idea!

    Simply add an extra parameter for the form (eg: (cleanctls as control, cleanfrm as Form) ), and within the function use that instead of "form1".

    Then to call the function simply specify the form too, eg:
    Code:
    RF Text1, Form1

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Re: Can I make a procedure|function to clean textbox on selected forms?

    Well, I tried that. It says Im doing an invalid use of property.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Can I make a procedure|function to clean textbox on selected forms?

    I have done similar things many times before, and it's worked well... can you show us the code you currently have, and tell us which line has the error?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Can I make a procedure|function to clean textbox on selected forms?

    This should work for you.
    Code:
    Public Sub ClearAllTB(pfFormName As Form)
    Dim ctrl As Control
        For Each ctrl In pfFormName.Controls
            If TypeOf ctrl Is TextBox Then
               ctrl.Text = vbNullString
            End If
        Next
    End Sub
    
    'on a form
    Private Sub cmdClear_Click()
    ClearAllTB Form1
    End Sub

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