Missing Forms

GaryEWheeler

New member
Local time
Today, 14:20
Joined
Jun 25, 2012
Messages
6
I'm having a strange problem. I'm writing code so I can open multiple copies of the same form. Here is the code I'm using.

Dim newfrm As Form

Set newfrm = New myFormName

newfrm.Visible = True
newfrm.Caption = "myCaption"

Here is the problem, when I use the command "Set newfrm = New ?????" the form I want to use doesn't show up in the list of objects. In fact, only 2 of the 7 forms currently in the project show up in the list.

Any ideas?

Gary
 
Here is the problem, when I use the command "Set newfrm = New ?????" the form I want to use doesn't show up in the list of objects. In fact, only 2 of the 7 forms currently in the project show up in the list.

Any ideas?

The way you are coding your form code is the more OO way of dealing with forms. (The less OO way would be using DoCmd type commands, such as DoCmd.OpenForm.

There is a bug that when opening forms via the class that the form name does not get set in the Forms collection as the key handle to identify the form via. One has to code in loop style, step through each Form in the Forms collection, and interrogate the form.Such as:

Code:
    'Refresh the prior window UI
    'Needed since this form was opened via its class and the
    'Forms Collection does not have the form name set as the key
    For Each frm In Forms
      If frm.Name = "quotes" Then
        Call frm.Refresh_Click(ObjUIValidationQuotesTbl.id)
        Exit For
      End If
    Next frm
I suspect something similar is what you have encountered.
 
Thanks for the info, however it didn't help. I'm using OO because I need to open multiple copies of the same from. DoCmd.OpenForm only opens the source form. Unless you know I secret I don't.
 
I understood and affirmed your use of OO as opposed to the DoCmd commands.

I was pointing out one known bug with Access using OO form code, and was suggesting that perhaps you have encountered another similar bug.

Perhaps get the code into a state where multiple copies of the same form is open, and take a spin through the Forms collection to see if you are able to detect which form is actually which.

More understandable now?
 
Unfortunately I can’t even see the form the first time to open it via OO. I can only the form via DoCmd, but that doesn’t help. Just not sure why only 2 of my 7 forms show up in VB code using OO.
 
Is Access even capable of having multiple instances of the same Form class open at the same time? If it is, I was not aware of it.
 
According to everything I have read and looked up yes. But, I'm having a lot of trouble with it.

Thanks for your help.
 
Code:
Dim newfrm As Form

[COLOR=Blue][B]Set newfrm = New myFormName[/B][/COLOR]
    
newfrm.Visible = True
newfrm.Caption = "myCaption"

rrrr???? In my code I refer to the form class as syntax Form_formname... where Form_ is automaticailly prefixed by Access / VBA.

Code:
Private WithEvents frmquotes As [COLOR=Blue][B]Form_quotes[/B][/COLOR]

Private Sub Quotes_Click()

  'Open the quotes dialog window via its class
  flgInitArchitecture = True
  [COLOR=Blue][B]Set frmquotes = New Form_quotes[/B][/COLOR]
  frmquotes.Visible = True

End Sub
I understood that the Class Name is actually the "Form_*" name, and minus the "Form_*" is the instance.

P.S. Oh, and in my working example I needed to place the class name in both blue spots actually.
 
Yes, that would be correct, however my I get an error my the User Defined Object doesn't exist even when you identify the form as Form_frmName.

Like I said, only 2 of my 7 forms can be identified this way.
 
To keep track of the instances of each form, you will need to keep your own list using a Dictionary. Everytime you create an instance, add it to a dictionary and refer to the dictionary for that instance (if needs be).

See if this link helps:

http://www.cpearson.com/excel/classes.aspx

Refer to the section, "Storing Multiple Objects In A Collection"
 

Users who are viewing this thread

Back
Top Bottom