Solved

Multiple instance of form ("New" giving error)

Posted on 2013-12-19
5
309 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 Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

708 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

13 Experts available now in Live!

Get 1:1 Help Now