Results 1 to 4 of 4
  1. #1
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182

    Copy and Pasting between frm and Subfrm

    Hello.

    I have a button on a form (frmWebsites) that displays information about websites. frmWebsites opens in a dialogue when you click a button in a subform (frmSub Beta Information). When I click the "Close and Save" button on frmWebsites, I want Access to copy and paste the value from a field in frmWebsites to a field in frmSub Beta Information. (However, the frmSub Beta Information will not always be open. In that case, I do not want to copy and paste anything). I have used the codes below to help me achieve this.



    Code:
    Option Compare Database
    
    Function IsFrmOpen(sFrmName As String) As Boolean
    On Error GoTo Error_Handler
     
        If Application.CurrentProject.AllForms(sFrmName).IsLoaded = True Then
            IsFrmOpen = True
        Else
            IsFrmOpen = False
        End If
     
    Error_Handler_Exit:
        On Error Resume Next
        Exit Function
     
    Error_Handler:
        MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
        Err.Number & vbCrLf & "Error Source: IsFrmOpen" & vbCrLf & "Error Description: " & _
        Err.Description, vbCritical, "An Error has Occured!"
        Resume Error_Handler_Exit
    End Function


    Code:
    If IsFrmOpen("frmSub Beta Information") = True Then
        Forms![frmSub Beta Information].tblWebsiteID = Me.tblWebsiteID
        DoCmd.Save acForm, "frmWebsite Information"
        DoCmd.Close acForm, "frmWebsite Information"
    Else
        DoCmd.Save acForm, "frmWebsite Information"
        DoCmd.Close acForm, "frmWebsite Information"
    End If
    End Sub
    The problem I have is that the code above does not account for a SUBFORM. frmSub Beta Information is actually a subform in frmAlpha. If I have just frmSub Beta Information open, Access will copy and paste between forms. But this will not happen if I have frm Sub Beta Information open WITHIN frmAlpha.

    Any thoughts?

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    see this link about how to refer to access objects

    http://access.mvps.org/access/forms/frm0031.htm

  3. #3
    zashaikh is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2017
    Posts
    182
    Ive been to that website plenty of times. Either I dont understand it or it doesnt have what I need

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    focus on the bit in red

    Not in these forms
    To refer to a form property, like RecordSource
    On Mainform Me.Parent.Parent.RecordSource Forms!Mainform.RecordSource
    On Sub 1 Me.Parent.RecordSource Forms!Mainform!Subform1.Form.RecordSource
    On Sub 2 Me.RecordSource Forms!Mainform!Subform1.Form!Subform2.Form.RecordS ource
    To refer to a control
    On Mainform Me.Parent.Parent!ControlName Forms!Mainform!ControlName
    On Sub 1 Me.Parent!ControlName Forms!Mainform!Subform1.Form!ControlName
    On Sub 2 Me!ControlName Forms!Mainform!Subform1.Form!Subform2.Form!Control Name

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

Similar Threads

  1. Replies: 2
    Last Post: 05-03-2016, 01:24 PM
  2. Replies: 2
    Last Post: 10-23-2014, 08:19 PM
  3. Search Box on subfrm
    By libraccess in forum Queries
    Replies: 1
    Last Post: 09-27-2013, 09:54 PM
  4. Replies: 2
    Last Post: 05-28-2013, 12:32 PM
  5. Copy and pasting data in form view help
    By Ash1402 in forum Forms
    Replies: 8
    Last Post: 10-13-2012, 12:36 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