|
Subject:
|
Closing a SubForm Only (SOLVED)
|
|
Posted By:
|
eusanpe
|
Post Date:
|
4/15/2008 4:33:29 PM
|
Hello All:
Here is my dilemna:
I have a mainform with command buttons for 'Add', 'Edit' and 'Exit'. This uses the mainform table. When I click 'Add' I hide the command buttons and display some fields that I can enter data and there are command buttons for 'Save', 'Undo' and 'Close'. When I click the 'Close' button, I remove all of the fields and I display the command buttons 'Add', 'Edit' and 'Exit' This works great.
When I click the 'Edit' button from the mainform I open up a subform and hide the 'Edit' button. This subform uses the subform table. The subform has the command buttons 'Save', 'Undo' and 'Close'. The issue I am having is that when I click the 'Close' button I can remove the fields from the subform but I can't close the subform and redisplay the 'Add', 'Edit' and 'Exit' buttons on the mainform. The DoCMD.Close command closes both forms.
How can I just close the subform while keeping the mainform open?
I am using Access 2003.
Thanks, Tony
|
|
Reply By:
|
jeremy1048
|
Reply Date:
|
4/15/2008 6:33:18 PM
|
It may be simpler to clear the sourceobject of the subform placeholder and make the placeholder invisible and then visible and reload the sourceobject when the button you want the subform to show is clicked.
The following is part of a option group code i use to hide and show subforms and a tab control (tbcasedetails) depending on what is clicked. the subform placeholder (subfileinspect) holds multiple different subforms depending on what is clicked.
Case 1 'case details Me.subfileinspect.SourceObject = "" Me.subfileinspect.Visible = False Me.tbcasedetails.Visible = True
Case 2 'correspondence If IsNull(arfirm) Then MsgBox "You must enter a firm before proceeding to correspondence.", vbCritical Me.arfirm.SetFocus End If If IsNull(aradviserid) Then MsgBox "You must enter an adviser before proceeding to correspondence.", vbCritical Me.cboaradviser.SetFocus End If If IsNull(clientname1) Then MsgBox "You must enter the client name before proceeding to correspondence", vbCritical Me.txtclientname1.SetFocus End If Me.tbcasedetails.Visible = False Me.subfileinspect.Visible = True If Me.subfileinspect.SourceObject <> "fsubinspectcalls2" Then Me.subfileinspect.SourceObject = "fsubinspectcalls2" End If Case 3 'training issues Me.tbcasedetails.Visible = False Me.subfileinspect.Visible = True If Me.subfileinspect.SourceObject <> "fsubtrainingissues" Then Me.subfileinspect.SourceObject = "fsubtrainingissues" End If
|
|
Reply By:
|
eusanpe
|
Reply Date:
|
4/16/2008 9:01:20 AM
|
Good morning:
Thanks for the reply. I load the sourceobject when I click the 'Edit' button. The 'Edit' button is on the mainform and the vba code associated with it is on the mainform.
The 'Close' button is on the subform and the vba code associated with it is on the subform. I need to close the subform when the 'Close' button is pressed and stay on the mainform.
Here is some of the code:
Mainform Code - (Record Source - Original_Control) ============================================================= 'This opens the subform when the Edit button is clicked and the Edit button is disabled.
Private Sub cmdEdit_Click() On Error GoTo Err_cmdEdit_Click txtMousewheel1.SetFocus cmdEdit.Top = 1260 cmdEdit.Left = 11279.952 Revision_Control_SubForm.Visible = True Revision_Control_SubForm.Top = 2040.048 Revision_Control_SubForm.Left = 7139.952 Exit_cmdEdit_Click: cmdEdit.Enabled = False Exit Sub
Err_cmdEdit_Click: MsgBox Err.Description Resume Exit_cmdEdit_Click
End Sub ============================================================
Subform Code (SourceObject Name - Revision_Control_SubForm) =========================================================== 'This will let me select an item
Private Sub cboRCName_AfterUpdate() Dim rs As Object Set rs = Me.Recordset.Clone rs.FindFirst "[lblRCName] = '" & Me![cboRCName] & "'" If Not rs.EOF Then Me.Bookmark = rs.Bookmark txtMousewheel2.SetFocus
End Sub ------------------------------------------------------ ' This will close the subform and mainform. I need it to just close the subform.
Private Sub cmdRCClose_Click() txtAllowSave = False txtMousewheel2.SetFocus On Error GoTo Err_cmdRCClose_Click 'lblRCName.Visible = False 'cboRCName.Visible = False 'lblRCVersion.Visible = False 'txtRCVersion.Visible = False 'lblRCModifications.Visible = False 'txtRCModifications.Visible = False 'lblRCModifier.Visible = False 'cboRCModifier.Visible = False 'lblRCModifiedDate.Visible = False 'dtRCOModifiedDate.Visible = False 'cmdRCSave.Visible = False 'cmdRCUndo.Visible = False 'cmdRCClose.Visible = False DoCMD.Close
Exit_cmdRCClose_Click: Exit Sub
Err_cmdRCClose_Click: MsgBox Err.Description Resume Exit_cmdRCClose_Click End Sub ==================================================================
Edit... I figured it out. I had to set focus away from the subform so I added. Me.Parent!txtMousewheel1.SetFocus
Then I added this command under the Private Sub cmdRCClose_Click() routine Me.Parent!Revision_Control_SubForm.Visible = False.
The following site has a great reference. http://www.mvps.org/access/forms/frm0031.htm
Thanks, Tony
|