Unable to set a form object

Posted on 2007-10-19
Last Modified: 2013-11-27
I have a really weird problem.  I want to set a form object.  My code is

   Dim frm As Form
   Set frm = Forms("frm_Enquiry")

I'm getting "Run-time error '2450':  Microsoft Access can't find the form 'frm_Enquiry' referred in the macro expression or Visual Basic code."

The form is named correctly and exists.

If I use the following syntax, it works:

   Dim frm As Form
   Set frm = Form_frm_Enquiry

But utiimately, I want to be able to enumerate to all the forms in my database and the latter syntax won't work for me.

Thanks for any help.
Question by:alk10
    LVL 65

    Accepted Solution

    >The form is named correctly and exists.
    It also has to be open in order for it to appear in the Forms() collection.
    LVL 65

    Expert Comment

    by:Jim Horn
    Do this in your Immediate Window:

    ?Forms.Count       'This returns the number of open forms.

    ?Forms(0).Name    'This returns the first open form's name

    ?Forms(1).Name    'This returns the second open form's name, etc.

    Author Comment

    I didn't realize the form had to be open.

    Thank you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
    In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
    Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now