Results 1 to 3 of 3
  1. #1
    TamworthBob is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    May 2020
    Posts
    7

    Open a second copy of a form that hs subforms

    I am using code from Alen j Browne to open a copy of a form (ContactDetails). The code below works fine but the subforms are not cleared and do not change when the combo box (cboStationName) is updated. Any Ideas?
    The code to open the new copy is:
    Private Sub Command256_Click()



    'Purpose: Open an independent instance of form frmClient.
    Dim frm As Form

    'Open a new instance, show it, and set a caption.
    Set frm = New Form_ContactDetails
    frm.Visible = True
    frm.Caption = frm.hwnd & ", ContactDetails Copy " & Now()

    'Append it to our collection.
    clnClient.Add Item:=frm, Key:=CStr(frm.hwnd)
    Set frm = Nothing

    End Sub
    Thanks in advance, Bob

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,411
    Possibly something to do with tgg he d Ed code behind your combo?

  3. #3
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296
    Quote Originally Posted by TamworthBob View Post
    Set frm = New Form_ContactDetails
    frm.Visible = True
    frm.Caption = frm.hwnd & ", ContactDetails Copy " & Now()
    Is the combobox bound to anything?
    Perhaps try something like
    frm.control("ComboBox").text = ""

    and for the subform perhaps it is using the same subform as the main since you only copied the main for it probably only created a new container control that references the same one.

    Code:
    Private Sub Command256_Click()
    
    'Purpose: Open an independent instance of form frmClient.
    Dim frm As Form, subfrm As Form
    
    Set subfrm = New Form_SubformName
    
    'Open a new instance, show it, and set a caption.
    Set frm = New Form_ContactDetails
    frm.Visible = True
    frm.Caption = frm.hwnd & ", ContactDetails Copy " & Now()
    frm.control("ComboBox").text = ""
    frm.control("SubformContainerName").SourceObject = subfrm
    
    'Append it to our collection.
    clnClient.Add Item:=frm, Key:=CStr(frm.hwnd)
    Set frm = Nothing
    
    End Sub
    Alternatively if you don't want to create a new subform you could write a loop to cycle through the subform controls and clear them all after the new form has been appended (or before).
    Hope that is the right fix for you!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 03-06-2023, 03:45 PM
  2. Replies: 8
    Last Post: 03-21-2021, 11:20 AM
  3. Copy a record and open in form
    By klnlsu in forum Programming
    Replies: 5
    Last Post: 05-17-2017, 10:34 AM
  4. Replies: 2
    Last Post: 09-17-2014, 04:55 PM
  5. Replies: 24
    Last Post: 03-04-2013, 06:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums