Passing Parameters to Form Object in VB6 
Author Message
 Passing Parameters to Form Object in VB6

Hi Collective Knowledge

        I am developing an application that has one form, that I instantiate
new Forms from.
Currently, I use the Tag property to pass a value to the formObj to use
in a SQL statement. This lets me use the same form for different
recordset views.
        like:
            Dim frmObj As Form
            Set frmObj = New frmProject
            frmObj.Tag = "PENDING"
            frmObj.Show

        in the form:
            Sub Form_Load()
                dim pstrSQL as string
                pstrSQL = "SELECT * FROM tblProject WHERE fldComplete = '" & me.Tag &
"'"

This method works fine. But, I think there must be a more elegant and
proper way to do this, through passing arguments to the form instance.

Can I declare arguments in the Form_Load module ?   ex.  Sub
Form_Load(gstrComplete as String)

How would I do this ?

Thanks...
        Joe



Sun, 20 Feb 2005 23:41:52 GMT  
 Passing Parameters to Form Object in VB6
You can not do this.

Form_Load is Event and Load MyForm has nothing to do with Form_Load

You can, hovewer use Property for what you need and check property on
Form_Paint or _Acivate.

Like make it required. Your code will be like:

Load MyForm    ' <- Form_Load will be executed only 1st time !
MyForm SQLStatement = "blah-blah"
MyForm.Show ' <- Form_Paint will be executed



Quote:
> Hi Collective Knowledge

> I am developing an application that has one form, that I instantiate
> new Forms from.
> Currently, I use the Tag property to pass a value to the formObj to use
> in a SQL statement. This lets me use the same form for different
> recordset views.
> like:
>     Dim frmObj As Form
>     Set frmObj = New frmProject
>     frmObj.Tag = "PENDING"
>     frmObj.Show

> in the form:
>     Sub Form_Load()
> dim pstrSQL as string
> pstrSQL = "SELECT * FROM tblProject WHERE fldComplete = '" & me.Tag &
> "'"

> This method works fine. But, I think there must be a more elegant and
> proper way to do this, through passing arguments to the form instance.

> Can I declare arguments in the Form_Load module ?   ex.  Sub
> Form_Load(gstrComplete as String)

> How would I do this ?

> Thanks...
> Joe



Mon, 21 Feb 2005 00:21:51 GMT  
 Passing Parameters to Form Object in VB6
Unfortuanately you cannot add parameters to the Form_Load event, however you
can create a Public Sub that you can pass parameters to and open the form
from there;

Dim frmObj As Form
Set frmObj = New frmProject
frmObj.FrmOpen "PENDING"

in the form:
Public Sub FrmOpen(strComplete As String)
    dim pstrSQL as string
    pstrSQL = "SELECT * FROM tblProject WHERE fldComplete = '" & _
                      strComplete & "'"
    'Any other code you want to run before form is shown
    Me.Show
End Sub

Bob

Quote:

> This method works fine. But, I think there must be a more elegant and
> proper way to do this, through



Quote:
> Hi Collective Knowledge

> I am developing an application that has one form, that I instantiate
> new Forms from.
> Currently, I use the Tag property to pass a value to the formObj to use
> in a SQL statement. This lets me use the same form for different
> recordset views.
> like:
>     Dim frmObj As Form
>     Set frmObj = New frmProject
>     frmObj.Tag = "PENDING"
>     frmObj.Show

> in the form:
>     Sub Form_Load()
> dim pstrSQL as string
> pstrSQL = "SELECT * FROM tblProject WHERE fldComplete = '" & me.Tag &
> "'"

> This method works fine. But, I think there must be a more elegant and
> proper way to do this, through passing arguments to the form instance.

> Can I declare arguments in the Form_Load module ?   ex.  Sub
> Form_Load(gstrComplete as String)

> How would I do this ?

> Thanks...
> Joe



Mon, 21 Feb 2005 01:21:27 GMT  
 Passing Parameters to Form Object in VB6

Quote:

> Unfortuanately you cannot add parameters to the Form_Load event, however you
> can create a Public Sub that you can pass parameters to and open the form
> from there;

> Dim frmObj As Form
> Set frmObj = New frmProject
> frmObj.FrmOpen "PENDING"

> in the form:
> Public Sub FrmOpen(strComplete As String)
>     dim pstrSQL as string
>     pstrSQL = "SELECT * FROM tblProject WHERE fldComplete = '" & _
>                       strComplete & "'"
>     'Any other code you want to run before form is shown
>     Me.Show
> End Sub

> Bob

> > This method works fine. But, I think there must be a more elegant and
> > proper way to do this, through



> > Hi Collective Knowledge

> > I am developing an application that has one form, that I instantiate
> > new Forms from.
> > Currently, I use the Tag property to pass a value to the formObj to use
> > in a SQL statement. This lets me use the same form for different
> > recordset views.
> > like:
> >     Dim frmObj As Form
> >     Set frmObj = New frmProject
> >     frmObj.Tag = "PENDING"
> >     frmObj.Show

> > in the form:
> >     Sub Form_Load()
> > dim pstrSQL as string
> > pstrSQL = "SELECT * FROM tblProject WHERE fldComplete = '" & me.Tag &
> > "'"

> > This method works fine. But, I think there must be a more elegant and
> > proper way to do this, through passing arguments to the form instance.

> > Can I declare arguments in the Form_Load module ?   ex.  Sub
> > Form_Load(gstrComplete as String)

> > How would I do this ?

> > Thanks...
> > Joe

Thank You Bob....

        This works great. Now I can pass multiple paramenters to my Form
Instance, without having to parse the Tag property. A much better way to
do this.

        One question.  I'm calling this Public Sub from a MDI form. When I
invoke frmObj.[list] (FrmOpen is not an Autolist member option). It is
available from the form. Can I make this Public Sub in the Form
accessible to the MDI form (not really necessary, but invokes a
question).

Thanks    .  . ..   You hit the nail right on the head.

        joe...



Mon, 21 Feb 2005 02:25:50 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Use a form object passed as a parameter

2. Pass an Object (a Form) as a parameter to an OCX: possible

3. Pass Parameter from form to form

4. How can I pass parameter from a form to another form

5. Trouble Passing VB6 Collection Object to VB6 Component in MTS

6. > passing vb6 optional byref parameter into c#

7. Passing Parameters from VB6 To Access

8. Passing parameters to querydefs in VB6

9. VB6 - Problem passing multiple parameters to Command SQL statement

10. Data Report in Vb6 - Passing Parameter

11. Help with passing parameters to CR9 from VB6

12. Pass Parameter to CR9 Report from VB6

 

 
Powered by phpBB® Forum Software