By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,461 Members | 2,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,461 IT Pros & Developers. It's quick & easy.

Checkbox on main form not checking subform

P: 59
I am trying to get my checkbox on my main form also to check the checkbox in the subform with the following code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Archived_Click()
  2. If Me.Archived = True Then
  3.     Me.subformTenantContacts.Archived = True
  4.     End If
  5. End Sub
but it is not working. Where am I going wrong?
May 2 '17 #1

✓ answered by PhilOfWalton

Is the NAME of the subform "subformTenantContacts" as opposed to the SourceObject?

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

Tab shouldn't matter

Phil

Share this Question
Share on Google+
16 Replies


PhilOfWalton
Expert 100+
P: 1,430
Try

Expand|Select|Wrap|Line Numbers
  1. Me.subformTenantContacts.Form!Archived = True
  2.  
If your subform is a continuous form, it should??? change the Archived Field only in the current record

Phil
May 2 '17 #2

P: 59
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.
May 2 '17 #3

P: 59
Does it matter it's a subform placed in a tab control?
May 2 '17 #4

PhilOfWalton
Expert 100+
P: 1,430
Is the NAME of the subform "subformTenantContacts" as opposed to the SourceObject?

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

Tab shouldn't matter

Phil
May 2 '17 #5

P: 59
Yes. The name of the subform is "suformTenantContacts".

If the Control means the name of the Checkbox, then yes, the Control is called Archived in both the main form and subform.
May 2 '17 #6

PhilOfWalton
Expert 100+
P: 1,430
Your reply states the subform is "suformTenantContacts". Note the missing "b" in "suB"

Phil
May 2 '17 #7

P: 59
Sorry, that's just a typo.
May 2 '17 #8

PhilOfWalton
Expert 100+
P: 1,430
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

Expand|Select|Wrap|Line Numbers
  1. Debug.Print Me.suformTenantContacts.name
  2.  
If that works add

Expand|Select|Wrap|Line Numbers
  1. Debug.Print Me.suformTenantContacts.Name
  2. Debug.Print Me.suformTenantContacts.Controls.Count
  3.  
Let me know progress

Phil
May 2 '17 #9

P: 59
The first
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Me.suformTenantContacts.name
  2.  
did not work.
May 3 '17 #10

P: 59
Think I've found a bit of the problem. Although my form is named subformTenantContacts 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.
May 3 '17 #11

P: 59
Got it!
Expand|Select|Wrap|Line Numbers
  1. If Me.Archived = True Then
  2.     Me.Tenant_Contacts.Form!Archived = True
  3.     ElseIf Me.Archived = False Then
  4.     Me.Tenant_Contacts.Form!Archived = False
  5.     End If
  6. End Sub
Thanks for the help.
May 3 '17 #12

PhilOfWalton
Expert 100+
P: 1,430
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_Contacts" as in your code?

Phil
May 3 '17 #13

P: 59
It is "Tenant_Contacts" 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!
May 3 '17 #14

NeoPa
Expert Mod 15k+
P: 31,398
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 :
Expand|Select|Wrap|Line Numbers
  1.     Me.Tenant_Contacts.Form.Archived = Me.Archived
  2. End Sub
This replaces all of :
Expand|Select|Wrap|Line Numbers
  1.     If Me.Archived = True Then
  2.         Me.Tenant_Contacts.Form!Archived = True
  3.     ElseIf Me.Archived = False Then
  4.         Me.Tenant_Contacts.Form!Archived = False
  5.     End If
  6. End Sub
May 3 '17 #15

P: 59
Thanks for the tip NeoPa. Will take this into my future coding escapades.
May 5 '17 #16

NeoPa
Expert Mod 15k+
P: 31,398
8-)

It's always good to see members progress from the advice.
May 6 '17 #17

Post your reply

Sign in to post your reply or Sign up for a free account.