Changing control value on subform from main form control (1 Viewer)

stevekos07

Registered User.
Local time
Yesterday, 22:11
Joined
Jul 26, 2015
Messages
174
I know this has probably been asked and answered several times, but I just don't seem to be able to get it right. I have a main form frmCallSheet, with a control Answered. This form has a subform control called sbfServiceContinuity, which contains a form frmServiceContinuity, which has a checkbox control chkContinueYes.

I want to set the value of chkContinueYes to True if chkAnswered is checked as True.

The code I am trying to use is:

If Me.Answered.Value = True Then

Me.sbfServiceContinuity.Form.chkContinueYes.Value = True

This doesn't seem to be working. The runtime error says that the method or data member is not found.

Can anyone help?
 

Solo712

Registered User.
Local time
Today, 01:11
Joined
Oct 19, 2012
Messages
828
I know this has probably been asked and answered several times, but I just don't seem to be able to get it right. I have a main form frmCallSheet, with a control Answered. This form has a subform control called sbfServiceContinuity, which contains a form frmServiceContinuity, which has a checkbox control chkContinueYes.

I want to set the value of chkContinueYes to True if chkAnswered is checked as True.

The code I am trying to use is:

If Me.Answered.Value = True Then

Me.sbfServiceContinuity.Form.chkContinueYes.Value = True

This doesn't seem to be working. The runtime error says that the method or data member is not found.

Can anyone help?

Have you tried
Code:
Me.[B]frm[/B]ServiceContinuity.Form.chkContinueYes.Value = True
?

Best,
Jiri
 

stevekos07

Registered User.
Local time
Yesterday, 22:11
Joined
Jul 26, 2015
Messages
174
Tried that too. Still an error.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 15:11
Joined
Jan 20, 2009
Messages
12,852
Your syntax looks correct. Carefully check the spelling on the line that breaks..
 

stevekos07

Registered User.
Local time
Yesterday, 22:11
Joined
Jul 26, 2015
Messages
174
Your syntax looks correct. Carefully check the spelling on the line that breaks..

Seems correct. I've tried both the container: sbfServiceContinuity and the subform itself frmServiceContinuity as the control reference but both return a runtime error.

I've triple checked the spelling, and it is correct. This is frustrating. There is something basic I'm missing here. :(
 

stevekos07

Registered User.
Local time
Yesterday, 22:11
Joined
Jul 26, 2015
Messages
174
Just wondering whether I should use a DoCmd.SetProperty method instead?
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 15:11
Joined
Jan 20, 2009
Messages
12,852
Try deleting the control and adding it to the form again.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:11
Joined
Feb 19, 2002
Messages
43,266
Me.sbfServiceContinuity.Form.chkContinueYes.Value = True

Is the correct syntax. Is sbfServiceContinuity the name of the subform CONTROL? It must be the Name property of the subform CONTROL, not the name of the subform.

Two problems.
1. Since subforms generally have multiple records, exactly WHICH record do you think you are updating when you reference the subform from the main form?
2. If you are trying to set the value in ALL subform records, then the field belongs in the parent record and NOT in the subfom record.
 

stevekos07

Registered User.
Local time
Yesterday, 22:11
Joined
Jul 26, 2015
Messages
174
Me.sbfServiceContinuity.Form.chkContinueYes.Value = True

Is the correct syntax. Is sbfServiceContinuity the name of the subform CONTROL? It must be the Name property of the subform CONTROL, not the name of the subform.

Two problems.
1. Since subforms generally have multiple records, exactly WHICH record do you think you are updating when you reference the subform from the main form?
2. If you are trying to set the value in ALL subform records, then the field belongs in the parent record and NOT in the subfom record.

In this case the records are in different tables, with the Master and Child based on the same client ID. There is only one subform in this form. sbfServiceContinuity is the name of the control, not the subform itself.

The reason it is a subform and not simply part of the main form is because the form frmServiceContinuity is accessible from another form as a pop-up dialog form.

I thought that I found the problem when I discovered that chkContinueYes had no source control assigned. But when I fixed that the code still caused an error.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:11
Joined
Feb 19, 2002
Messages
43,266
My comments seem to have missed the mark.
Does the SUBFORM have multiple records? If it does, which of the many records are you trying to update?

What event is this code located in? Sounds like the code may not be in the correct event.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 15:11
Joined
Jan 20, 2009
Messages
12,852
Does the SUBFORM have multiple records? If it does, which of the many records are you trying to update?

The Current Record would be updated of course, if it worked but I can't see how the question is relevant.

The error is "the method or data member cannot be found".

We have assumed it is the subform reference that is the problem but on the information given, it could also be Me.Answered. Depends where the break happens.

We have not heard the result of my suggestion of deleting and replacing the control. I have seen that action fix similar problems more than once.

If that doesn't work I would try replacing the subform control and after that, rebuilding the subform itself. The controls and any code can simply be copied and pasted into a new form.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:11
Joined
Feb 19, 2002
Messages
43,266
Galaxiom, I asked the question to make sure that stevekos07 knew the answer. I didn't ask it because I didn't know the answer. Most people who attempt to update child records in this manner do not understand that in a properly structured relational database, this action makes no sense. Plus, they have no clue that they have to ensure that the record they want to update is actually the current record since it may not necessarily be the first visible record.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 15:11
Joined
Jan 20, 2009
Messages
12,852
Most people who attempt to update child records in this manner do not understand that in a properly structured relational database, this action makes no sense.

Ah! The OP's original question could indeed be non sequitur.
 

stevekos07

Registered User.
Local time
Yesterday, 22:11
Joined
Jul 26, 2015
Messages
174
Galaxiom, I asked the question to make sure that stevekos07 knew the answer. I didn't ask it because I didn't know the answer. Most people who attempt to update child records in this manner do not understand that in a properly structured relational database, this action makes no sense. Plus, they have no clue that they have to ensure that the record they want to update is actually the current record since it may not necessarily be the first visible record.

Thanks Pat and co. Yes it turns out indeed that I was chasing a rabbit down the wrong hole. I have abandoned the structure and instead incorporated the necessary fields in the main form. I was trying to update a field in the subform that had the same name but different source to the field I was trying to reference. Once I discovered this it was obvious I was never going to get the structure to work properly.

This is what happens when one is under pressure to try to produce a solution without insisting on the necessary time to think through the structure of everything properly.

I have managed to get a lot of bang from my fairly amateur buck with this project, but sometimes I do find that I have sometimes have to turn around and go back to more familiar ground when things start going pear-shaped :eek:.
 

Users who are viewing this thread

Top Bottom