Run-time error '2450':Microsoft Access can't find the form

C

Chas

Hi, I'm having trouble with the following code:

Private Sub Customer_ID_DblClick(Cancel As Integer)
Dim objAccess As Object
Dim Pathstring As String
Dim cmdForm As Object
Dim OpenedForm As Object
Dim FormName As String
Dim objColForms As Access.Forms
Dim numForms As Long
Pathstring = "c:\DB-FE\DB-FE.mdb"
Set objAccess = CreateObject("Access.Application")
Call objAccess.OpenCurrentDatabase(Pathstring, False)
Set objColForms = objAccess.Forms
numForms = objColForms.Count
FormName = "Registrant"
Set cmdForm = objAccess.DoCmd
Set OpenedForm = objColForms.Item(FormName)
Call cmdForm.OpenForm(FormName, acNormal, , "Customer_ID=" & _
objAccess.Forms.Item(FormName).Customer_ID, acFormPropertySettings, acWindowNormal)
End Sub

I have similar code working on other DBs, this particular one gives
me the following when I try to run it, from the line "Set OpenedForm = objColForms.Item(FormName)":

Run-time error '2450':

Microsoft Access can't find the form 'Registrant' referred to in a macro expression or Visual Basic code.

Thing is after it opens the Access application I can open the form from it, but it can't find it.
 
G

George Nicholson

The Forms collection consists only of currently open forms. Your code fails
when you try to set a reference to a form before it has been opened ("Access
can't find..."). This type of thing is one reason why IsLoaded() functions
were created.... :)

However, the AllForms collection includes, as you might have guessed, all
forms, but backward compatibility might be an issue. It did not exist in
Access 97. It does exist in 2002/XP but doesn't appear in its "What's New"
list, so I assume it was added in 2000.

HTH,
 
C

Chas

The Forms collection consists only of currently open forms. Your code
fails when you try to set a reference to a form before it has been
opened ("Access can't find..."). This type of thing is one reason why
IsLoaded() functions were created.... :)

However, the AllForms collection includes, as you might have guessed,
all forms, but backward compatibility might be an issue. It did not
exist in Access 97. It does exist in 2002/XP but doesn't appear in its
"What's New" list, so I assume it was added in 2000.

HTH,

Thanks, George.

I'll see what I can do with this, I had looked at the Allforms previously,
but didn't pursue it with all the vigor I should have. Would you like me to
update you if I'm successful?

Chas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top