Checkbox on main form not checking subform

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • glat
    New Member
    • Dec 2016
    • 62

    Checkbox on main form not checking subform

    I am trying to get my checkbox on my main form also to check the checkbox in the subform with the following code
    Code:
    Private Sub Archived_Click()
    If Me.Archived = True Then
        Me.subformTenantContacts.Archived = True
        End If
    End Sub
    but it is not working. Where am I going wrong?
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    #2
    Try

    Code:
    Me.subformTenantContacts.Form!Archived = True
    If your subform is a continuous form, it should??? change the Archived Field only in the current record

    Phil

    Comment

    • glat
      New Member
      • Dec 2016
      • 62

      #3
      I had tried this before however it gave me a Compile Error: "Method or data member not found" even though I can see the form in the Class Objects window at the side of the code.

      Comment

      • glat
        New Member
        • Dec 2016
        • 62

        #4
        Does it matter it's a subform placed in a tab control?

        Comment

        • PhilOfWalton
          Recognized Expert Top Contributor
          • Mar 2016
          • 1430

          #5
          Is the NAME of the subform "subformTenantC ontacts" as opposed to the SourceObject?

          Do you have a Control called "Archived" as opposed to the ControlSource being Archived?

          Tab shouldn't matter

          Phil

          Comment

          • glat
            New Member
            • Dec 2016
            • 62

            #6
            Yes. The name of the subform is "suformTenantCo ntacts".

            If the Control means the name of the Checkbox, then yes, the Control is called Archived in both the main form and subform.

            Comment

            • PhilOfWalton
              Recognized Expert Top Contributor
              • Mar 2016
              • 1430

              #7
              Your reply states the subform is "suformTenantCo ntacts". Note the missing "b" in "suB"

              Phil

              Comment

              • glat
                New Member
                • Dec 2016
                • 62

                #8
                Sorry, that's just a typo.

                Comment

                • PhilOfWalton
                  Recognized Expert Top Contributor
                  • Mar 2016
                  • 1430

                  #9
                  I can't see what's wrong, so let's work gently at the problem

                  so comment out the kine that won't compile and add

                  Code:
                  Debug.Print Me.suformTenantContacts.name
                  If that works add

                  Code:
                  Debug.Print Me.suformTenantContacts.Name
                  Debug.Print Me.suformTenantContacts.Controls.Count
                  Let me know progress

                  Phil

                  Comment

                  • glat
                    New Member
                    • Dec 2016
                    • 62

                    #10
                    The first
                    Code:
                    Debug.Print Me.suformTenantContacts.name
                    did not work.

                    Comment

                    • glat
                      New Member
                      • Dec 2016
                      • 62

                      #11
                      Think I've found a bit of the problem. Although my form is named subformTenantCo ntacts in the Forms window, it is called "Tenant Contact" in the Other Tab of the Property Sheet on the form. It now stalls at ".Form!" with Method or data member not found.

                      Comment

                      • glat
                        New Member
                        • Dec 2016
                        • 62

                        #12
                        Got it!
                        Code:
                        If Me.Archived = True Then
                            Me.Tenant_Contacts.Form!Archived = True
                            ElseIf Me.Archived = False Then
                            Me.Tenant_Contacts.Form!Archived = False
                            End If
                        End Sub
                        Thanks for the help.

                        Comment

                        • PhilOfWalton
                          Recognized Expert Top Contributor
                          • Mar 2016
                          • 1430

                          #13
                          Yes, I thought it was a problem with the name of the subform.

                          I personally always call the subform on the main form exactly the same as the name in the Navigation Page. You obviously have cracked it, and I assume there is a Typo, but is the subform name "Tenant Contact" as in your message or "Tenant_Contact s" as in your code?

                          Phil

                          Comment

                          • glat
                            New Member
                            • Dec 2016
                            • 62

                            #14
                            It is "Tenant_Contact s" as in my code. I really don't know why it is a different name. Would have saved me a lot of time and effort it was!

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32633

                              #15
                              I'd just like to point out that attention to detail is enormously important in development. Particularly in Office applications where the syntax isn't checked as heavily for you be the compiler. It will save you much heart-ache when you take the point on board.

                              Another very helpful tip that you'll benefit from immensely if you take it on board, is that proper indenting of code can be enormously helpful and save you a lot of effort further down the line. OTOH badly indented code, such as you've posted, is much worse even than none at all. It will confuse a reader and give clues that are actually false. A very dangerous practice.

                              Anyway, As I see that this is pretty well resolved already (and I've assigned a Best Answer for you) I'll just offer up a minor change to your code to make it easier to maintain :
                              Code:
                                  Me.Tenant_Contacts.Form.Archived = Me.Archived
                              End Sub
                              This replaces all of :
                              Code:
                                  If Me.Archived = True Then
                                      Me.Tenant_Contacts.Form!Archived = True
                                  ElseIf Me.Archived = False Then
                                      Me.Tenant_Contacts.Form!Archived = False
                                  End If
                              End Sub

                              Comment

                              Working...