Results 1 to 10 of 10
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Disabling a subform

    I have a subform that I'm trying to disable. When I click on a check, I want it to enable and disable when it's not clicked. Here's the code:
    Private Sub ContrabandFound_Click()
    If (ContrabandFound) Then
    Me.ContrabandDescr.Enabled = True
    Me.frmContrabandTypeSubF.Enabled = True
    Else
    Me.ContrabandDescr.Enabled = False
    Me.frmContrabandTypeSubF.Enabled = False
    End If



    End Sub

    The subform (frmContrabandTypeSubF) will not disable. The code works fine for the field (ContrabandDescr). How can I disable that subform when the check mark is not checked?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What is name of the subform container control that holds the form? Reference the container control. I always name container different from object it holds, like: ctrDetails.
    If container and form have same name, your code should work. Visually, the subform will appear same but should not be able to edit data when disabled.

    Code can be simplified:
    Code:
    Private Sub ContrabandFound_Click()
            Me.ContrabandDescr.Enabled = Me.ContrabandFound
            Me.ctrDetails.Enabled = Me.ContrabandFound
    End Sub
    The code is not working for a field, code is setting properties of controls.
    If ContrabandDescr is a textbox or combobox, can use Conditional Formatting instead of VBA.
    I also usually name controls different from field, such as tbxContraband.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    What is a container control?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    A subform or subreport is created by placing a subform/subreport container control on form or report. The container holds a table/query/form/report as defined in SourceObject property. https://support.office.com/en-us/art...esubformwizard
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I understand the subform. I'm just not understanding what the container control is. I can't find that in the property of the subform.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You won't. It's not a property. As described in linked tutorial, it is a control that can be selected from the Design tab. The container control has a SourceObject property. This is were you indicate what object (table/query/form/report) the container should hold.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    The subform is called [frmContrabandTypeSubF]
    Master Field: PublicContactID
    Child Field: PublicContactID
    It's getting information from table: [tblContrabandType]

    Does that help?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Sounds like the container and the form it holds have the same name. But you do not show content of the SourceObject property so only a guess.

    Probably should also have code in form Current event.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I put it in the for Current event. Here's the code:


    If (SearchConducted) Then
    Me.cboReasonForSearch.Enabled = True
    Else
    Me.cboReasonForSearch.Enabled = False
    End If

    If (ContrabandFound) Then
    Me.ContrabandDescr.Enabled = True
    Me.frmContrabandTypeSubF.Enabled = True
    Else
    Me.ContrabandDescr.Enabled = False
    Me.frmContrabandTypeSubF.Enabled = False
    End If

    If (ArrestMade) Then
    Me.cboReasonForArrest.Enabled = True
    Else
    Me.cboReasonForArrest.Enabled = False
    End If

    It works for the fields on the form, but not for the subform.

  10. #10
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I figured it out. The code does work. I have some other code in the Current event. That code contradicted this one. I put it at the end of the code and it works perfectly. Thanks for the time.

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

Similar Threads

  1. Disabling Objects
    By Eranka in forum Access
    Replies: 2
    Last Post: 05-28-2018, 07:00 AM
  2. Disabling Options
    By Eranka in forum Access
    Replies: 3
    Last Post: 01-23-2018, 06:18 AM
  3. Disabling Fields
    By dolovenature in forum Programming
    Replies: 2
    Last Post: 09-16-2012, 07:45 PM
  4. Disabling fields
    By bursteffect in forum Access
    Replies: 1
    Last Post: 08-30-2012, 12:54 PM
  5. Disabling A Button
    By cksm4 in forum Programming
    Replies: 8
    Last Post: 10-05-2010, 02:07 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