How to pass argument to a form? 
Author Message
 How to pass argument to a form?

Hi people,

Does anybody know how to load a form sending a parameter like functions?

Example: something like to put the arguments on Form_Load (a as integer)

Best regards, MCC.



Fri, 21 Sep 2001 03:00:00 GMT  
 How to pass argument to a form?
There are several of achieving this and personally I like creating a public
property and then set this property before showing the form.

--
HTH

VB-Joker
MCSE

PLEASE post ALL replies to newsgroup!

Quote:
> Hi people,

> Does anybody know how to load a form sending a parameter like functions?

> Example: something like to put the arguments on Form_Load (a as integer)

> Best regards, MCC.



Fri, 21 Sep 2001 03:00:00 GMT  
 How to pass argument to a form?

Quote:

>Does anybody know how to load a form sending a parameter like functions?

(Edited repeat of numerous other earlier posts on this subject)

There are two ways. Which one to use depends on what will work best for your
application.

The first is to setup public properties procedures for your form. Since
accessing a property of a form will cause it to load, this may not always be
a practical solution. I most often use this method with MDI Child forms.

My usual method, which is what I use for modal dialog forms, is to create my
own Show like method to load, show, and unload the form. Below is some
sample code that shows how this would work with a modal dialog with an OK
and Cancel button...

======

Option Explicit

Dim mbCancel As Boolean

Private Sub Form_Load()
' nothing goes here
End Sub

Public Function DisplayForm(sStuff As String) As Boolean

    Load Me

    ' do what you need to do with sStuff here

    Me.Show vbModal
    If Not mbCancel Then
        '
        ' get new value for sStuff here if it's to be passed back
        ' or do other stuff for an OK button press
        '
    End If
    DisplayForm = Not mbCancel
    Unload Me
End Function

Private Sub cmdCancel_Click()
    mbCancel = True
    Me.Hide
End Sub

Private Sub cmdOK_Click()
    mbCancel = False
    Me.Hide
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode <> vbFormCode Then
        mbCancel = True
        Me.Hide
        Cancel = True
    End If
End Sub

======

The form would be called something like this....

     If frmStuffDialog.DisplayForm(sLocalVariable) Then

Frank Carr



Fri, 21 Sep 2001 03:00:00 GMT  
 How to pass argument to a form?
You need a Public Sub on the receiving form to accept the parameter.
For example, in frmForm1 you create the public sub "DoIt":

Public Sub Doit(intParameter1 as Integer, intParameter2 as Integer)
    Dim intParam1 as Integer
    Dim intParam2 as Integer

    intParam1 = intParameter1
    intParam2 = intParameter2

End Sub

This sub would accept 2 passed parameters. This sub would run before the
frmForm1.FormLoad.

To pass the parameters from frmForm2:

On frmForm2, a statement would call the sub on Form1 like this:

frmForm1.Doit 5, 7

This would pass the integers "5" and "7" into frmForm1's intParam1 and
intParam2. Any other statements in the frmForm1 DoIt sub would then process,
and then frmForm1's LoadForm would process.

HTH

-Dennis Leahy



Fri, 21 Sep 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How do I pass arguments to a form?

2. HELP !!! PASS ARGUMENTS FOR EVENT/FORM PROCEDURES?

3. Arguments : Passing Arguments containing <">

4. Newbie, correct syntax passing arguments as form names

5. Passing form field type constant as an argument

6. passing a form as argument not working !

7. Passing arguments to new forms

8. Passing arguments to forms

9. Passing Arguments to a Form

10. Argument Passing to forms.

11. Passing arguments to a form

12. passing arguments from one form to another

 

 
Powered by phpBB® Forum Software