Can you pass form to a module (*.bas)?? 
Author Message
 Can you pass form to a module (*.bas)??

Hello,

I am in between a beginner and intermediate in VB6.  I have 2 forms,
frmA and frmB.  Many text boxes and combo boxes on each form have the
same name.  Is  there a way of calling a public function to clear the
fields in both forms that can be viable for both forms?  -If so, what is
it?  Do I need to pass the form and how do I do that???  Thanks.  A code
snippet and/or syntax would be greatly appreciated.

Thank You



Fri, 06 Dec 2002 03:00:00 GMT  
 Can you pass form to a module (*.bas)??
To clear ALL textboxes on a form, you could use something like...

'============
Public Sub ClearBoxes(frm As Form)
   'Usage: From a form, Call ClearBoxes(Me). From anywhere, Call
ClearBoxes(FormName)
   Dim iFor As Integer
   Dim sTypeName As String

   With frm
      For iFor = 0 To .Controls.Count - 1
         sTypeName = TypeName(.Controls(iFor))
         If sTypeName = "TextBox" Then
            .Controls(iFor).Text = ""
         End If
      Next iFor
   End With
End Sub
'============

Or if you just want to clear specific boxes,

'============
Public Sub ClearSomeBoxes(frm As Form)
   With frm
      .txtThisBox.Text = ""
      .txtThatBox.Text = ""
   End With
End Sub
'============


Quote:
> Hello,

> I am in between a beginner and intermediate in VB6.  I have 2 forms,
> frmA and frmB.  Many text boxes and combo boxes on each form have the
> same name.  Is  there a way of calling a public function to clear the
> fields in both forms that can be viable for both forms?  -If so, what
is
> it?  Do I need to pass the form and how do I do that???  Thanks.  A
code
> snippet and/or syntax would be greatly appreciated.

> Thank You



Fri, 06 Dec 2002 03:00:00 GMT  
 Can you pass form to a module (*.bas)??
Nick,

Public Sub ClearFields(frm as Form)
    frm.Text1.Text=""
    frm.Combo1.Clear
    'etc.
End Sub

Call this with:

ClearFields FormA
ClearFields FormB

There is no error checking in above routine to make sure Text1 and Combo1
are valid controls on the form. You should either add some error checking or
make sure all referenced controls exist on any form passed to the
subroutine.

--
Tim Rude


(remove NOSPAM. for correct email address)

[Please reply via the newsgroup so all can benefit]


Quote:
> Hello,

> I am in between a beginner and intermediate in VB6.  I have 2 forms,
> frmA and frmB.  Many text boxes and combo boxes on each form have the
> same name.  Is  there a way of calling a public function to clear the
> fields in both forms that can be viable for both forms?  -If so, what is
> it?  Do I need to pass the form and how do I do that???  Thanks.  A code
> snippet and/or syntax would be greatly appreciated.

> Thank You



Fri, 06 Dec 2002 03:00:00 GMT  
 Can you pass form to a module (*.bas)??
put this in a module

Public Sub ClearText(txt1 As Textbox, txt2 As Textbox)
txt1.Text = ""
txt2.Text = ""
End Sub

put this in a textbox or something:

ClearText NameOfTextBox, NameOfTextBox2

:-D

Quote:
> Hello,

> I am in between a beginner and intermediate in VB6.  I have 2 forms,
> frmA and frmB.  Many text boxes and combo boxes on each form have the
> same name.  Is  there a way of calling a public function to clear the
> fields in both forms that can be viable for both forms?  -If so, what is
> it?  Do I need to pass the form and how do I do that???  Thanks.  A code
> snippet and/or syntax would be greatly appreciated.

> Thank You



Fri, 06 Dec 2002 03:00:00 GMT  
 Can you pass form to a module (*.bas)??
how about

Public sub ClearForm(frm as form)
    dim ctl as control

    for each ctl in frm.controls
        if typeof ctl  is TextBox then ' or whatever other control type you
care about
            ctl.text = ""
        end if
    next
end sub

This way is more reusable between forms which may have different names.

Quote:

>Hello,

>I am in between a beginner and intermediate in VB6.  I have 2 forms,
>frmA and frmB.  Many text boxes and combo boxes on each form have the
>same name.  Is  there a way of calling a public function to clear the
>fields in both forms that can be viable for both forms?  -If so, what is
>it?  Do I need to pass the form and how do I do that???  Thanks.  A code
>snippet and/or syntax would be greatly appreciated.

>Thank You



Sun, 08 Dec 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Can you pass form to a module (*.bas)??

2. Can you pass form to a module (*.bas)??

3. Can you pass form to a module (*.bas)??

4. vb4: bas modules and form modules

5. Help passing array to bas module sub

6. Passing input box value from Form Module to report module

7. Canned AcctReceivable Module needed!

8. Accessing Form Controls From a .BAS module

9. Please help: Updating form controls from a separate BAS module

10. Please help: Updating form controls from a separate BAS module

11. Updating form controls using outside BAS modules

12. Adding a form to project creates module(*.bas)

 

 
Powered by phpBB® Forum Software