Use a form object passed as a parameter 
Author Message
 Use a form object passed as a parameter

In a global-level error handling sub, I have passed the name the
form that created the error, like this:

  Public Sub HandleErrors (Optional ByVal pobjSourceForm As Form)

I can't seem to use the object in my code module. For instance, I need
to determine whether is was passed as a parameter, using something like

        If pobjSourceForm  = Nothing Then

or something similar, and I'd like to close the form from my module
with something like

   Unload pobjSourceForm    or
    pobjSourceForm.Hide

but neither of these work.

Can I do what I'm trying to do? If so, any help with the code structure
would be appreciated.



Tue, 27 Jan 2004 03:35:15 GMT  
 Use a form object passed as a parameter
optional parameters MUST be defined as a variant.

First, check the ismissing(pobjSourceForm) value to determine
if it was passed.

Then next, check the
    If Type Of pobjSourceForm is form then
        we know it was a form, so check the form props that you want to
check.

Hope this helps.

D.


Quote:
> In a global-level error handling sub, I have passed the name the
> form that created the error, like this:

>   Public Sub HandleErrors (Optional ByVal pobjSourceForm As Form)

> I can't seem to use the object in my code module. For instance, I need
> to determine whether is was passed as a parameter, using something like

>         If pobjSourceForm  = Nothing Then

> or something similar, and I'd like to close the form from my module
> with something like

>    Unload pobjSourceForm    or
>     pobjSourceForm.Hide

> but neither of these work.

> Can I do what I'm trying to do? If so, any help with the code structure
> would be appreciated.



Tue, 27 Jan 2004 03:57:37 GMT  
 Use a form object passed as a parameter
Quote:
> optional parameters MUST be defined as a variant.

Not really.. the following works..

'=============Form1 Code
Option Explicit

Private Sub Command1_Click()
   Call Form2.Test(Me)
End Sub

'=============Form2 Code
Option Explicit

Public Sub Test(Optional Frm As Form)
   If Not Frm Is Nothing Then
      Debug.Print Frm.Name
   End If
End Sub
'=============

Maybe you were talking about the IsMissing function.. that only works on
Variants.


Quote:
> optional parameters MUST be defined as a variant.

> First, check the ismissing(pobjSourceForm) value to determine
> if it was passed.

> Then next, check the
>     If Type Of pobjSourceForm is form then
>         we know it was a form, so check the form props that you want to
> check.

> Hope this helps.

> D.



> > In a global-level error handling sub, I have passed the name the
> > form that created the error, like this:

> >   Public Sub HandleErrors (Optional ByVal pobjSourceForm As Form)

> > I can't seem to use the object in my code module. For instance, I need
> > to determine whether is was passed as a parameter, using something like

> >         If pobjSourceForm  = Nothing Then

> > or something similar, and I'd like to close the form from my module
> > with something like

> >    Unload pobjSourceForm    or
> >     pobjSourceForm.Hide

> > but neither of these work.

> > Can I do what I'm trying to do? If so, any help with the code structure
> > would be appreciated.



Tue, 27 Jan 2004 04:33:09 GMT  
 Use a form object passed as a parameter

Quote:

> optional parameters MUST be defined as a variant.

Is this in reference to some old version or something?  Doesn't seem to be
the case with VB 6.0.


Tue, 27 Jan 2004 04:37:30 GMT  
 Use a form object passed as a parameter
Its likely that case that I haven't been over the Docs in a while...  My
bad...

IsMissing will only work on a variant optional param to my knowledge...
... unless that has changed too...  Man, I feel old today...

D.


Quote:

> > optional parameters MUST be defined as a variant.

> Is this in reference to some old version or something?  Doesn't seem to be
> the case with VB 6.0.



Tue, 27 Jan 2004 04:47:58 GMT  
 Use a form object passed as a parameter


Quote:
> optional parameters MUST be defined as a variant.

In VB4, yes....


Tue, 27 Jan 2004 05:13:42 GMT  
 Use a form object passed as a parameter
OK, I got it, but I still can't seem to close the
form that way. My code

Public Sub HandleErrors(Optional ByVal pobjSourceForm As Form)
      If pobjSourceForm Is Nothing
         Exit Sub
      Else
         pobjSourceForm.Hide   ' unload doesn't work either
      End If
End Sub

doesn't close the form passed to the function, even
though the form name is being passed properly. Can I
do this somehow?

Thanks for the help, guys.


Quote:
> In a global-level error handling sub, I have passed the name the
> form that created the error, like this:

>   Public Sub HandleErrors (Optional ByVal pobjSourceForm As Form)

> I can't seem to use the object in my code module. For instance, I need
> to determine whether is was passed as a parameter, using something like

>         If pobjSourceForm  = Nothing Then

> or something similar, and I'd like to close the form from my module
> with something like

>    Unload pobjSourceForm    or
>     pobjSourceForm.Hide

> but neither of these work.

> Can I do what I'm trying to do? If so, any help with the code structure
> would be appreciated.

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


Tue, 27 Jan 2004 06:57:27 GMT  
 Use a form object passed as a parameter
Never mind, it's working fine. I'm having some other problem,
but this one is solved. Thanks again for the help.


Quote:
> In a global-level error handling sub, I have passed the name the
> form that created the error, like this:

>   Public Sub HandleErrors (Optional ByVal pobjSourceForm As Form)

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


Tue, 27 Jan 2004 07:31:30 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Passing Parameters to Form Object in VB6

2. Using events of objects passed as parameters

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

4. Passing multiple parameters to Access query using Form List Box

5. Passing Parameters to stored parameter queries using VB 5's Data Controls

6. Passing parameters to SQLServer using a Pass-Through query

7. Passing a report object as an arguement to a form using prtdevmode and name

8. Pass Parameter from form to form

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

10. Linking Form Objects in HTML to other Form Objects using VBScript

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

12. passing custom objects as parameters to procedures

 

 
Powered by phpBB® Forum Software