Run Time error '2450'

  • Thread starter Thread starter John Bruen
  • Start date Start date
J

John Bruen

I received the message on this line below: Set frm = Forms
(passform)

Run-time error '2450'
Microsoft Access can't find the form 'Frm1' referred to in
a macro expression or Visual Basic Code.

Function ShowProps
Dim objAcObj As AccessObject
Dim objCurProj As CurrentProject
Dim objCurData As CurrentData

Set objCurProj = Application.CurrentProject
Set objCurData = Application.CurrentData

For Each objAcObj In objCurProj.AllForms
ListControlProps (objAcObj.Name)
Next objAcObj
End Function


Function ListControlProps(passform)
Dim ctl As Control
Dim prp As Property
Dim frm As Form

Set frm = Forms(passform) <========== line in error

For Each ctl In frm.Controls
Debug.Print ctl.Properties("Name")
For Each prp In ctl.Properties
Debug.Print vbTab & prp.Name & " = " & prp.Value
Next prp
Next ctl
End Function
 
The statement

Set frm = Forms(passform)

will give you the error if the "passform" is not currently loaded in the
memory. Note that you are using 2 different Collections here:

* AllForms Collection contains all the forms in your database. So your code
will iterate though all the forms.

* Forms Collection contains only the *currently-open* forms.

Unless you open all the forms in the database, there will be forms that in
AllForms Collection but do not belong to the Forms Collection.
 
Van

Are you telling me that there is no collection that I
cannot access the properties unless the form is open? I
thought the passform is loaded in memory when passing the
parm from the previous function.

John
 
See comments in-line.

--
HTH
Van T. Dinh
MVP (Access)



John Bruen said:
Van

Are you telling me that there is no collection that I
cannot access the properties unless the form is open?

Sorry, I don't know of any such collection besides the Forms Collection. On
the other hand, I can always open the Form in Design mode and hidden so that
nothing appear on screen but the Form is a member of the Forms Collection.

I thought the passform is loaded in memory when passing the
parm from the previous function.

No. You only pass the Name which is simply a String, nothing about opening /
loading the Form.
 
Back
Top