469,658 Members | 1,835 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,658 developers. It's quick & easy.

Application can't find opened form???

Can someone please explain why the following code
raises error 2450?...
Note:
frmTest is a simple form with code behind form so it
can be instantiated through the form's class module.

Public Sub sbTest()
On Error GoTo errHandler
Dim frm As Access.Form

'create new instance of the class Form_frmTest
Set frm = New Form_frmTest
'make form visible
frm.Visible = True
'get form's name
MsgBox Forms("frmTest").Name 'err 2450 is generated here. Why?...

bye:
Set frm = Nothing
Exit Sub
errHandler:
Select Case Err
Case 2450 'can't find form
MsgBox "What is hapening here!???..." & vbCrLf & "Can't find this
form???"
Case Else
MsgBox Err() & vbCrLf & Error$()
End Select
Resume bye
End Sub

Thanks for ANY input ,
---
(-: a s i l b a . p t ;-)
Nov 12 '05 #1
7 6869
TC
Just as a matter of interest, why are you opening the form with New, instead
of using OpenForm? When you use OpenForm, the form certainly is added to the
Forms collection...

HTH,
TC
"a s i l b a . p t" <as*******************@hotmail.com> wrote in message
news:3f*********************@news.telepac.pt...
Can someone please explain why the following code
raises error 2450?...
Note:
frmTest is a simple form with code behind form so it
can be instantiated through the form's class module.

Public Sub sbTest()
On Error GoTo errHandler
Dim frm As Access.Form

'create new instance of the class Form_frmTest
Set frm = New Form_frmTest
'make form visible
frm.Visible = True
'get form's name
MsgBox Forms("frmTest").Name 'err 2450 is generated here. Why?...

bye:
Set frm = Nothing
Exit Sub
errHandler:
Select Case Err
Case 2450 'can't find form
MsgBox "What is hapening here!???..." & vbCrLf & "Can't find this
form???"
Case Else
MsgBox Err() & vbCrLf & Error$()
End Select
Resume bye
End Sub

Thanks for ANY input ,
---
(-: a s i l b a . p t ;-)

Nov 12 '05 #2
"TC" <a@b.c.d> wrote in news:1068341629.447304@teuthos:
Just as a matter of interest, why are you opening the form with New,
instead of using OpenForm? When you use OpenForm, the form certainly is
added to the Forms collection...

HTH,
TC
"a s i l b a . p t" <as*******************@hotmail.com> wrote in message
news:3f*********************@news.telepac.pt...
Can someone please explain why the following code
raises error 2450?...
Note:
frmTest is a simple form with code behind form so it
can be instantiated through the form's class module.

Public Sub sbTest()
On Error GoTo errHandler
Dim frm As Access.Form

'create new instance of the class Form_frmTest
Set frm = New Form_frmTest
'make form visible
frm.Visible = True
'get form's name
MsgBox Forms("frmTest").Name 'err 2450 is generated here. Why?...

bye:
Set frm = Nothing
Exit Sub
errHandler:
Select Case Err
Case 2450 'can't find form
MsgBox "What is hapening here!???..." & vbCrLf & "Can't find
this
form???"
Case Else
MsgBox Err() & vbCrLf & Error$()
End Select
Resume bye
End Sub

Thanks for ANY input ,
---
(-: a s i l b a . p t ;-)


If we use the DoCmd object only one instance of the form is opened. So
Access has no problem finding Forms("NameofForm").

But if we open the form by instantiating its class, we can have multiple
copies of a form, and Access, quite properly IMO, recognizes the potential
for multiple instances of forms with the same name, and declines to allow
index reference by name to these forms, or even these forms.

Code below to illustrate.

Sub temp()
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
Debug.Print Forms.Count '1
Debug.Print Forms("Form1").Name 'Form1
DoCmd.Close acForm, "Form1"
End Sub

Sub temp2()
Dim frm(9) As Form_Form1
Dim z As Long
For z = 0 To 9
Set frm(z) = New Form_Form1
frm(z).Visible = True
Debug.Print frm(z).Name
Next z
Erase frm
End Sub

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #3
TC

"Lyle Fairfield" <Mi************@Invalid.Com> wrote in message
news:Xn*******************@130.133.1.4...
"TC" <a@b.c.d> wrote in news:1068341629.447304@teuthos:
Just as a matter of interest, why are you opening the form with New,
instead of using OpenForm? When you use OpenForm, the form certainly is
added to the Forms collection...

HTH,
TC
"a s i l b a . p t" <as*******************@hotmail.com> wrote in message
news:3f*********************@news.telepac.pt...
Can someone please explain why the following code
raises error 2450?...
Note:
frmTest is a simple form with code behind form so it
can be instantiated through the form's class module.

Public Sub sbTest()
On Error GoTo errHandler
Dim frm As Access.Form

'create new instance of the class Form_frmTest
Set frm = New Form_frmTest
'make form visible
frm.Visible = True
'get form's name
MsgBox Forms("frmTest").Name 'err 2450 is generated here. Why?...

bye:
Set frm = Nothing
Exit Sub
errHandler:
Select Case Err
Case 2450 'can't find form
MsgBox "What is hapening here!???..." & vbCrLf & "Can't find
this
form???"
Case Else
MsgBox Err() & vbCrLf & Error$()
End Select
Resume bye
End Sub

Thanks for ANY input ,
---
(-: a s i l b a . p t ;-)


If we use the DoCmd object only one instance of the form is opened. So
Access has no problem finding Forms("NameofForm").

But if we open the form by instantiating its class, we can have multiple
copies of a form, and Access, quite properly IMO, recognizes the potential
for multiple instances of forms with the same name, and declines to allow
index reference by name to these forms, or even these forms.

Code below to illustrate.

Sub temp()
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
DoCmd.OpenForm "Form1"
Debug.Print Forms.Count '1
Debug.Print Forms("Form1").Name 'Form1
DoCmd.Close acForm, "Form1"
End Sub

Sub temp2()
Dim frm(9) As Form_Form1
Dim z As Long
For z = 0 To 9
Set frm(z) = New Form_Form1
frm(z).Visible = True
Debug.Print frm(z).Name
Next z
Erase frm
End Sub

Ok, thanks for the info. I thought it might be that, but was not sure. I
assume the point of Sub temp2(), is that none of those form instances will
appear in the Forms collection? (you are showing their names from their
instance references, but not from the Forms collecion)

TC

Nov 12 '05 #4
"TC" <a@b.c.d> wrote in news:1068344395.768084@teuthos:
Ok, thanks for the info. I thought it might be that, but was not sure. I
assume the point of Sub temp2(), is that none of those form instances will
appear in the Forms collection? (you are showing their names from their
instance references, but not from the Forms collecion)

TC


They'll all be items in the forms collection. But they all have the same name
so to reference them individually it seems one needs to use a numeric
reference.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #5
Your code works for me, as long as it is called from a command button on frmTest. This is
similar to the example shown in MSKB 210248:

http://support.microsoft.com/default...b;en-us;210248

If I attempt to run your code by itself, in a stand alone module, I can see frmTest open
but I also get the same error 2450 that you are getting. I can send you a sample DB that
works on my PC if you want me to.

Tom

____________________________________________

"a s i l b a . p t" <as*******************@hotmail.com> wrote in message
news:3f*********************@news.telepac.pt...

Can someone please explain why the following code
raises error 2450?...
Note:
frmTest is a simple form with code behind form so it
can be instantiated through the form's class module.

Public Sub sbTest()
On Error GoTo errHandler
Dim frm As Access.Form

'create new instance of the class Form_frmTest
Set frm = New Form_frmTest
'make form visible
frm.Visible = True
'get form's name
MsgBox Forms("frmTest").Name 'err 2450 is generated here. Why?...

bye:
Set frm = Nothing
Exit Sub
errHandler:
Select Case Err
Case 2450 'can't find form
MsgBox "What is hapening here!???..." & vbCrLf & "Can't find this
form???"
Case Else
MsgBox Err() & vbCrLf & Error$()
End Select
Resume bye
End Sub

Thanks for ANY input ,
---
(-: a s i l b a . p t ;-)

Nov 12 '05 #6
Hi all,

I also tried this:
-- if you run the code by itself, in a stand alone module it also works ... when frmtest is open

Arno R
"Tom Wickerath" <AO***********************@comcast.net> schreef in bericht
news:Dv********************@comcast.com...
Your code works for me, as long as it is called from a command button on frmTest. This is
similar to the example shown in MSKB 210248:

http://support.microsoft.com/default...b;en-us;210248

If I attempt to run your code by itself, in a stand alone module, I can see frmTest open
but I also get the same error 2450 that you are getting. I can send you a sample DB that
works on my PC if you want me to.

Tom


Nov 12 '05 #7
I can perfectly understand Mr. Lyle's point of view,
though I do think It would be reasonable to expect
referencing the form by name would not error,
since only one form is added to the forms collection.
Anyway, I just turned around this issue,
by using a numeric reference to the form instance,
as sugested.

Thank you ALL for the valid input!
---
(-: a s i l b a . p t ;-)

"Lyle Fairfield" <Mi************@Invalid.Com> wrote in message
news:Xn*******************@130.133.1.4...
"TC" <a@b.c.d> wrote in news:1068344395.768084@teuthos:
Ok, thanks for the info. I thought it might be that, but was not sure. I
assume the point of Sub temp2(), is that none of those form instances will appear in the Forms collection? (you are showing their names from their
instance references, but not from the Forms collecion)

TC
They'll all be items in the forms collection. But they all have the same

name so to reference them individually it seems one needs to use a numeric
reference.

--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)

Nov 12 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Andrus | last post: by
2 posts views Thread by aagarwal8 | last post: by
7 posts views Thread by mxdevit | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.