Copy and Pasting between frm and Subfrm

NadiaVKhan

Registered User.
Local time
Today, 07:42
Joined
Mar 8, 2017
Messages
27
Hello.



I have a button on a form (frmBusiness) that displays information about Business. frmBusiness opens in a dialogue when you click a button in a subform (frmSub Beta Information). When I click the "Close and Save" button on frmBusiness, I want Access to copy and paste the value from a field in frmBusiness 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].tblBusinessID = Me.tblBusinessID

DoCmd.Save acForm, "frmBusines Information"

DoCmd.Close acForm, "frmBusines Information"

Else

DoCmd.Save acForm, "frmBusines Information"

DoCmd.Close acForm, "frmBusines 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?
 
I have been taken to that same link plenty of times, but I am still having difficulty.

I have been told to utilize this: "Me!Subform1.Form!ControlName"

However, what does "Me" refer to here? It should refer to [frmBusiness Information]. If thats the case, then would I replace "Subform1" with "frmBeta" (my subform) and replace ".form" with ".frmAlpha", my primary form?

This appears to be mixing up my forms. I want Me(frmBusiness).tblBusinessID to = frmBeta (subform of frmAlpha)
 
Me refers to the object the code is in/behind. You can simply use the full form reference if you aren't sure:

Forms!Mainform!Subform1.Form!ControlName
 

Users who are viewing this thread

Back
Top Bottom