Need help with object references 
Author Message
 Need help with object references

Looking through my VB4 projects, I can't find code where I have done this
before.  It is too simple to have to resort to the newsgroups, but I can't get
it figured out.  I'm using VB5 Enterprise.  In my menu (on an MDI form named
frmMain) I have a list os possible windows the user can open.  If a window is
open it has a check beside it.  When a user closes a window I want the check to
disappear.  Here is the code I am using.

Private Sub Form_Unload(cancel as Integer)
     frmMain.mnuInfoForm.Checked = False
End Sub

When executing I get a run time error 426.  The error message says "Only one
MDI Form allowed".  I've tried using "MDIForm.mnuInfoForm.Checked = False"
and I get the object required error.  Any body know what I'm doing wrong?  I
know I've done this before in VB4, I just can't find any examples of it at
home, and I no longer work where I did it.

Tim Crockett
Paisley Rainbow Studios



Thu, 25 Jan 2001 03:00:00 GMT  
 Need help with object references
If I understood correctly, you have a menu where each option represents a
form the user can load or unload.

So, if you have a menu named 'mnuTest', with an option 'opcForm1' in an MDI
parent form named 'frmMain', you can place a check mark next to the
'opcForm1' option by using:

    Private Sub opcform1_Click()
            Form1.Show
            frmMain.opcform1.Checked = True
    End Sub

where Form1 is an MDI child form.

to remove the check mark, you can use:

    Private Sub Form_Unload(Cancel As Integer)
        frmMain.opcform1.Checked = False
    End Sub

in the MDI child form.

I've tested this solution briefly and it seems to work

vmlf.


Quote:
>Looking through my VB4 projects, I can't find code where I have done this
>before.  It is too simple to have to resort to the newsgroups, but I can't
get
>it figured out.  I'm using VB5 Enterprise.  In my menu (on an MDI form
named
>frmMain) I have a list os possible windows the user can open.  If a window
is
>open it has a check beside it.  When a user closes a window I want the
check to
>disappear.  Here is the code I am using.

>Private Sub Form_Unload(cancel as Integer)
>     frmMain.mnuInfoForm.Checked = False
>End Sub

>When executing I get a run time error 426.  The error message says "Only
one
>MDI Form allowed".  I've tried using "MDIForm.mnuInfoForm.Checked = False"
>and I get the object required error.  Any body know what I'm doing wrong?
I
>know I've done this before in VB4, I just can't find any examples of it at
>home, and I no longer work where I did it.

>Tim Crockett
>Paisley Rainbow Studios




Sun, 28 Jan 2001 03:00:00 GMT  
 Need help with object references
Sounds like you have a global variable defined somewhere that points to your
MDI Parent form. The app wizard does this for you, I think, in a Sub Main,
as in:

In a Module:
Public fMainForm As frmMain

Sub Main()
    Set fMainForm = New frmMain
    fMainForm.Show
End Sub

Now, you MUST always reference the MDI Parent by fMainForm. If you try to
call it by its name (frmMain in your example), VB thinks you want to load
another instance, which is not allowed for MDI Parent forms. Change the
frmMain in the Form_Unload to the variable fMainForm, and you'll be OK.

Jonas
TRION Technologies

Quote:
>Private Sub Form_Unload(cancel as Integer)
>     frmMain.mnuInfoForm.Checked = False
>End Sub

>When executing I get a run time error 426.  The error message says "Only
one
>MDI Form allowed".  I've tried using "MDIForm.mnuInfoForm.Checked = False"
>and I get the object required error.  Any body know what I'm doing wrong?
I
>know I've done this before in VB4, I just can't find any examples of it at
>home, and I no longer work where I did it.

>Tim Crockett
>Paisley Rainbow Studios




Mon, 05 Feb 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. object model - need help referencing specific cells

2. Need help in resolving circular references between objects

3. Need help finding missing objects/references for a VB program

4. Passing an object reference by reference where the object has a default property

5. Please help with error: Object reference not set to an instance of an object

6. MSGraph 97 - need a reference - and need help with problems

7. need Reference to running Access97 object

8. Need object reference to a window

9. Project 2002 automation - need object reference

10. Need reference to currently opened IE application object

11. Referencing object in form in code / Subform reference problem in code

12. reference to a non-shared member requires an object reference

 

 
Powered by phpBB® Forum Software