Solved

Multiple instance of form ("New" giving error)

Posted on 2013-12-19
5
311 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

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…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

777 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