|
-
Mar 8th, 2007, 02:51 PM
#1
Thread Starter
Addicted Member
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
-
Mar 8th, 2007, 02:56 PM
#2
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:
-
Mar 8th, 2007, 07:55 PM
#3
Thread Starter
Addicted Member
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.
-
Mar 9th, 2007, 08:59 AM
#4
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?
-
Mar 9th, 2007, 09:19 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|