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 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?