Results 1 to 9 of 9
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Form: How to sense open as a child or independently

    I have a form with a command button. If the form is open as a child, I want to make the command button invisible. How do I sense when the form is open as a child?

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Try this code in the Form_Load event of your main form
    It assumes your button is in the subform

    Code:
    Private Sub Form_Load()Dim Ctrl As Control
    
        For Each Ctrl In Me.Controls
        
            Select Case Ctrl.ControlType
                Case acSubform
                    Ctrl.Form.btnToHide.Visible = False
            
            End Select
        
        Next Ctrl
    
    End Sub
    NOTE: I took this code from a thread at another forum https://www.access-programmers.co.uk...d.php?t=297204
    Several other good ideas in the same thread
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    It assumes your button is in the subform
    Yes.

    Bombs on setting of "cmdHERE"

    Click image for larger version. 

Name:	000.jpg 
Views:	8 
Size:	64.8 KB 
ID:	32281

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    This worked................

    Code:
    Private Sub Form_Open(Cancel As Integer)
    
        If HasParent Then
            Me.cmdHERE.Visible = False
            Me.lblHere.Visible = False
        End If
    
    End Sub
    
    Private Sub cmdHERE_Click()
    
    strmappingret = ExcelToAccess
    Me.Requery
    If Len(strmappingret) > 0 Then
        MsgBox "Highlighted names require correction."
    End If
    
    End Sub
    
    
    Private Property Get HasParent() As Boolean
    On Error GoTo handler
      HasParent = TypeName(Me.Parent.Name) = "String"
      Exit Property
    handler:
    End Property

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Excellent. That was Mark Klein's code I believe.
    I've not tried his code myself but was involved in that thread

    BTW if the label is associated with the button you shouldn't need to specify that as well
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    BTW if the label is associated with the button you shouldn't need to specify that as well
    Command button in the midst of a label:

    Click image for larger version. 

Name:	001.jpg 
Views:	8 
Size:	21.2 KB 
ID:	32282

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Interesting....
    You can of course use a label as a command button with its own click event
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    You can of course use a label as a command button with its own click event
    Yes, I do that frequently with column headings to control data sorting. I isolated the "HERE" command from the surrounding text purposefully because I know how the users of the current App like to hover over text while they read.

  9. #9
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    You could also use:

    Code:
    Private Sub Form_Load()
      If SysCmd(acSysCmdGetObjectState, acForm, "YourFormName") = 0 Then
       CommandButtonName.Visible = False
      Else
       CommandButtonName.Visible = True
     End If
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Criteria Error that makes no sense
    By RayMilhon in forum Queries
    Replies: 2
    Last Post: 11-22-2016, 12:28 PM
  2. Analyze Data Fields Independently
    By roberth in forum Reports
    Replies: 1
    Last Post: 12-12-2014, 06:12 PM
  3. Does this table relationship make sense?
    By MatthewGrace in forum Database Design
    Replies: 9
    Last Post: 10-05-2014, 03:59 PM
  4. Replies: 8
    Last Post: 05-23-2014, 02:19 PM
  5. Child Record Created, but won't display in child form
    By CementCarver in forum Programming
    Replies: 1
    Last Post: 04-10-2013, 12:42 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