Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a specific form instance

Status
Not open for further replies.

johnmidcap

Programmer
Oct 12, 2009
7
US
Good morning. Can someone point me in the correct direction about how to reference a specific form instance in Access 2007.

For example, I have three of the same form opened as instances (i.e. a user is looking up three different customer detail records at the same time). I need the program to update one of these form instances with new information.

Is there any way to do this?

I am applying a different caption to each form instance, here is a sample of the code:


Set frmNewform = New Form_frmAffiliations
frmNewform.lstAffiliations.RowSource = strSQL
frmNewform.txtNo = Me.txtNo
frmNewform.txtName = Me.txtBusName
frmNewform.SetFocus
frmNewform.Caption = Me.txtBusName & " Affiliations "
clnClient.Add Item:=frmNewform, Key:=CStr(frmNewform.hWnd)

I have been searching the web for a while to figure this out, but to no avail.

Thank you.
 
Normally you manage your form in a collection. Then you can call them by name. Here is a demo of two forms added to a collection and then setting properties of each

Code:
Dim myFrms As Collection

Public Sub manageFrmInstance()
  Dim frm As Form_Employees
  Set myFrms = New Collection
  Set frm = New Form_Employees
  myFrms.Add frm, "FormA"
  Set frm = New Form_Employees
  myFrms.Add frm, "FormB"
  With myFrms("FormA")
    .Visible = True
    .Detail.BackColor = vbRed
  End With
  With myFrms("FormB")
    .Visible = True
    .Detail.BackColor = vbBlue
  End With
End Sub
 
The collection needs to be at the module level in scope. If it is dimensioned in the procedure then as soon as the procedure finishes it would go out of scope.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top