Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 15th, 2008, 04:33 PM
Authorized User
Points: 336, Level: 6
Points: 336, Level: 6 Points: 336, Level: 6 Points: 336, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
Posts: 73
Thanks: 6
Thanked 0 Times in 0 Posts
Default Closing a SubForm Only (SOLVED)

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 With Quote
  #2 (permalink)  
Old April 15th, 2008, 06:33 PM
Authorized User
 
Join Date: May 2007
Location: , , .
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 With Quote
  #3 (permalink)  
Old April 16th, 2008, 09:01 AM
Authorized User
Points: 336, Level: 6
Points: 336, Level: 6 Points: 336, Level: 6 Points: 336, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
Posts: 73
Thanks: 6
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem solved bhavna .NET Framework 1.x 1 March 7th, 2007 12:20 PM
Form & Subform Closing w/Completion Check SarahL Access 4 June 2nd, 2006 07:22 AM
My Homework (I solved it) yui0329 C# 1 June 10th, 2005 11:25 AM
Problem Solved. blackdevil1979 Beginning VB 6 0 March 22nd, 2005 09:55 PM
Filter Subform B Based on Field in Subform A SerranoG Access VBA 3 June 18th, 2004 12:23 AM



All times are GMT -4. The time now is 07:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.