Solved

Multiple instance of form ("New" giving error)

Posted on 2013-12-19
5
312 Views
Last Modified: 2014-01-09
Hi,  (ACCESS 2013)

I want to be able to open my access form multiple times.
I saw the code below on the internet.


Private Sub cmdOpenNewCust_Click()
   Set frmX = New Form_Customers
   frmX.setfocus
End Sub

However, the "NEW" on the second line seems to cause problems.
"User-defined Type Not Defined".

Why am I getting this error?
0
Comment
Question by:Patrick O'Dea
  • 5
5 Comments
 
LVL 57
ID: 39729059
Is 'Customers' the name of the form?

Jim.
0
 
LVL 57
ID: 39729079
Just caught it.  Should be:

Private Sub cmdOpenNewCust_Click()

   Dim frmX as Form_Customers

   Set frmX = New Form_Customers

   frmX.setfocus

End Sub
0
 
LVL 57
ID: 39729081
Note that you can also do:

 Dim frmX as Form

Jim.
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 39729088
Also, since your just straying into this area, a couple of other comments:

1. When you start using multiple forms, you can't reference them by name anymore.  Something like this:

 Forms("Customers").Caption = "Customer " & Me.txtCustID

 because they all have the same name.   You need to either:

a. keep track of the ordnial in the forms collection
b. keep a collection of form object references yourself.

Also, because this is an instance of a class, you can't switch the instance into design view (which is a bad idea anyway) and all changes you make to an instance are temporary.  They won't be saved when the form closes.

Jim.
0
 
LVL 57
ID: 39729094
oh and one other comment; you test procedure as written will never show a form.

When a new form instance is created, it's visible property is false.  You need to set it true.  More important however is that as soon as the object variable goes out of scope, your instance is destroyed.

The best way to handle that is have a collection at module level that will not go out of scope.

Jim.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

791 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