How to declare variables set in form proc but used after form unloaded 
Author Message
 How to declare variables set in form proc but used after form unloaded

Hi again,

Word 97...

I need to know how to declare variables set in form proc but used after form
unloaded.

I'm setting my variable values in my cmdOK_Click procedure, but I need to
use them after I unload the form, either back in the AutoNew module or in
the next user form.  Where do I declare those variables, and would I just
use Dim statements?

Natelle



Sun, 25 Sep 2005 11:15:12 GMT  
 How to declare variables set in form proc but used after form unloaded
Hi Natelle

If you use the code I posted in the "Return to macro after unloading form
in cmdOK_click" thread you can access the forms controls before you unload
the from:

Public Sub AutoNew
    Dim frmWO As frmWordOccurs

    Set frmWO = New frmWordOccurs
    frmWO.Show

    MsgBox "Value from form control: " & frmWO.txtMyName.Text

    Unload frmWO
    Set frmWO = Nothing
End Sub

The above example assumes you have a TextBox control called "txtMyName" in
your form.

If you need to return a value from a variable (not a control) as long as
the variable is declared Private you can use a Property Get procedure. Ok,
this code in the Form:

Private mstrMyName As String

Private Sub UserForm_Initialize()
    mstrMyName = "Peter Hewett"
End Sub

Private Sub btnOK_Click()
    Me.Hide
End Sub

Public Property Get MyName() As String
    MyName = mstrMyName
End Property

This in AutoNew:

Public Sub AutoNew
    Dim frmWO As frmWordOccurs

    Set frmWO = New frmWordOccurs
    frmWO.Show

    MsgBox "Value from form property: " & frmWO.MyName

    Unload frmWO
    Set frmWO = Nothing
End Sub

I hope this makes things clear + Cheers - Peter



Quote:
> Hi again,

> Word 97...

> I need to know how to declare variables set in form proc but used after
> form unloaded.

> I'm setting my variable values in my cmdOK_Click procedure, but I need
> to use them after I unload the form, either back in the AutoNew module
> or in the next user form.  Where do I declare those variables, and would
> I just use Dim statements?

> Natelle



Sun, 25 Sep 2005 12:11:04 GMT  
 How to declare variables set in form proc but used after form unloaded
Peter,

Thanks.  I won't be able to try this for a bit as I have other stuff to do.
I appreciate it, and will definitely try it, but I already moved my code out
of AutoNew and put it all into the event procedures.  It  didn't quite work
perfectly, however, and I want to try your method.

Natelle


Quote:
> Hi Natelle

> If you use the code I posted in the "Return to macro after unloading form
> in cmdOK_click" thread you can access the forms controls before you unload
> the from:

> Public Sub AutoNew
>     Dim frmWO As frmWordOccurs

>     Set frmWO = New frmWordOccurs
>     frmWO.Show

>     MsgBox "Value from form control: " & frmWO.txtMyName.Text

>     Unload frmWO
>     Set frmWO = Nothing
> End Sub

> The above example assumes you have a TextBox control called "txtMyName" in
> your form.

> If you need to return a value from a variable (not a control) as long as
> the variable is declared Private you can use a Property Get procedure. Ok,
> this code in the Form:

> Private mstrMyName As String

> Private Sub UserForm_Initialize()
>     mstrMyName = "Peter Hewett"
> End Sub

> Private Sub btnOK_Click()
>     Me.Hide
> End Sub

> Public Property Get MyName() As String
>     MyName = mstrMyName
> End Property

> This in AutoNew:

> Public Sub AutoNew
>     Dim frmWO As frmWordOccurs

>     Set frmWO = New frmWordOccurs
>     frmWO.Show

>     MsgBox "Value from form property: " & frmWO.MyName

>     Unload frmWO
>     Set frmWO = Nothing
> End Sub

> I hope this makes things clear + Cheers - Peter



> > Hi again,

> > Word 97...

> > I need to know how to declare variables set in form proc but used after
> > form unloaded.

> > I'm setting my variable values in my cmdOK_Click procedure, but I need
> > to use them after I unload the form, either back in the AutoNew module
> > or in the next user form.  Where do I declare those variables, and would
> > I just use Dim statements?

> > Natelle



Wed, 28 Sep 2005 03:31:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Form level variables not being released when form is unloaded in VB5.0

2. Using variables declared in a different form

3. Forms Collection: Using it to Open Forms by Passing the Form Name as a String Variable

4. Unloading modal owner form also unloads modal form?

5. Call a proc using a string variable for the proc name

6. declaring form dynamic startup variables?

7. Unload a form does not unload declared variables!!!! Is that TRUE?????????

8. Unloading a form does not reset the variables declared in that form!!! Is that TRUE???????

9. unload form clears variables ?

10. Unloading forms, and public variables...

11. Load/Unload form with variable

12. Cannot assign a variable declared as a string to a variable declared as data type

 

 
Powered by phpBB® Forum Software