[AccessD] Loading more than one instance of a form

Mark A Matte markamatte at hotmail.com
Mon Jun 26 14:03:56 CDT 2006


Something like this??????????????????????????...Out of Solutions.mdb

Option Compare Database
Option Explicit

' Public variables that will be used to keep track of form instances.

Dim strMultiInstKey As String
Dim frmCustomers As Form_Customers

Public Property Get MultiInstKey() As String
	' Define the custom MultiInstKey property.
	MultiInstKey = strMultiInstKey
End Property

Public Property Let MultiInstKey(strVal As String)
	' Define the custom MultiInstKey property.
	strMultiInstKey = strVal
End Property

Public Sub RemoveFormInstance(strWhich As String)
	' Removes the instance of the Customers form specified by
	' strWhich from the collection.
	colCustomerForms.Remove strWhich
End Sub

Private Sub Form_Open(Cancel As Integer)
	' Initialize strMultiInstKey.
	strMultiInstKey = ""
End Sub

Private Sub View_Click()

	Dim frmNewInst As Form_Customers

	Const conFormDoesNotExist = 5

	On Error Resume Next
	' Check to see if instance of the form exists in the collection already.
	Set frmNewInst = colCustomerForms(Me!CustomerID)
	If Err = conFormDoesNotExist Then
		' Form does not exist.
		Set frmNewInst = New Form_Customers

		'Set form properties, including custom MultiInstKey property.
		With frmNewInst
			.MultiInstKey = Me!CustomerID

.AllowAdditions = False
			.AllowDeletions = False
			.NavigationButtons = False
			.RecordSelectors = False
			.RecordSource = "Select * from Customers Where Customers.CustomerID = """ 
& Me!CustomerID & """;"
			.Requery
			.Visible = True
		End With

		colCustomerForms.Add Item:=frmNewInst, Key:=Me!CustomerID
	Else
		' Form exists. Switch focus to it.
		frmNewInst.SetFocus
		DoCmd.Restore
	End If

End Sub
>From: "JWColby" <jwcolby at colbyconsulting.com>
>Reply-To: Access Developers discussion and problem 
>solving<accessd at databaseadvisors.com>
>To: "'Access Developers discussion and problem 
>solving'"<accessd at databaseadvisors.com>
>Subject: Re: [AccessD] Loading more than one instance of a form
>Date: Sun, 25 Jun 2006 09:36:11 -0400
>
>Eric,
>
>This is what I meant when I said that there was a document collection
>somewhere.  I used to use this syntax when I built a widget for working on
>forms in design view.  Unfortunately, that does not solve the problem of
>getting a handle to the form opened.
>
>If you run Docmd.Open doc.name ONCE then you can get a handle to that form
>using currentdb.forms("FormNameJustOpened").  Unfortunately if you open the
>same form several times using that same syntax,
>
>Docmd.Open doc.name
>Set MyFormPointer1=currentdb.forms("FormNameJustOpened")
>Docmd.Open doc.name
>Set MyFormPointer2=currentdb.forms("FormNameJustOpened")
>
>Does not work
>
>Apparently the forms all go into the currentdb.forms() collection, but
>because they all have the same name, the second instance cannot be
>retrieved.  Or perhaps the second instance is never instanced at all?  I
>have never actually looked at currentdb.forms().count to see if the second
>and subsequent instance ever actually makes it into that collection.
>
>In any event I can't get a pointer to the second and subsequent form
>instance which is my objective.
>
>I can open multiple instances till the cows come home using
>Dim MyFormCollection as collection
>While 1
>	Set MyFormPointer = form_MyFormName
>	MyFormCollection.Add MyFormPointer
>Wend
>
>BUT...
>
>Set MyFormPointer = form_MyFormName
>
>Means I have hardcoded the set statement to the name of ONE SPECIFIC FORM
>form_MyFormName
>
>The reason I am trying to do this is that (for example) if you had a bunch
>of list tables consisting of a PK and a field (CI_ID, CI_CityName)...
>
>You could build a single list form, open that form, change the recordsource
>and bind the controls to the two fields, whatever they may be.  Thus you
>could be have one form for every list table with just two fields instead of
>a new form for each.
>
>That is just one example of where this would be useful.
>
>John W. Colby
>Colby Consulting
>www.ColbyConsulting.com
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of StaRKeY
>Sent: Sunday, June 25, 2006 8:54 AM
>To: 'Access Developers discussion and problem solving'
>Subject: Re: [AccessD] Loading more than one instance of a form
>
>John,
>
>Is this what you're looking for?
>You can open or change forms, reports, modules etc... Without them being
>open!
>
>Sub John
>Dim doc as doa.document, db as dao.database
>
>   Set db=Currentdb
>   For each doc in db.containers("forms").documents
>	debug.print doc.name
>	docmd.open doc.name,acDesign,acHidden
>	'do whatever you want in designmode
>	docmd.close doc.name, True (save changes)
>   Next doc
>   Set db=nothing
>   Set doc=nothing
>End sub
>
>Forms = forms
>Reports = reports
>Macro's = scripts
>Modules = modules (moduletype ==> module or classmodule)
>
>Regards,
>Eric
>
>--
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com





More information about the AccessD mailing list