Solved

Multiple instance of form ("New" giving error)

Posted on 2013-12-19
5
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

762 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