Passing value to subform

D

Debbiedo

I have a main form called CIT Data Entry Form
I have a subform called CIT SubForm

TransApproval.Value is an option button in my main form
txtCITAppr has a control source in the subform that is a yes/no format
in its associated table

I want to say that if TransApproval.Value = 1 , then txtCITAppr = Yes
else txtTransAppr = No.

I can't seem to get the syntax right. Ideas anyone?

Here is my latest feeble atttempt.

Thanks

-------------------------------------------------------------
If Me!TransApproval.Value = 1 Then

Forms.("CIT Data Entry Form").CIT SubForm.txtCITAppr ="Yes"

Else:

Forms.("CIT Data Entry Form").CIT SubForm.txtCITAppr ="No"

End If
 
K

Klatuu

There are a few problems. First, you really should not use spaces in names.
But, if you must, you have to enclose the name in brackets so Access will
understand them.
You don't need the : after the Else. That is only when you are doing in In
Line If statemet.

Also you need to be clear on subforms and how they work. What is unclear is
whether CIT SubForm is the name of the form being used as a subform or it is
the name of the subform control on the main form. You do not use the name of
the form being used as a subform, you use the name of the subform control on
the main form. The actual form name is only used in the Source Object
property of the subform control so it knows what form to load as a subform.
You have to use the word Form between the name of the subform control because
Form is the name used to reference the form that is the source object of the
subform control. Then you use the name of the control on the form being used
as a subform.
You don't have to use the full qualifier since the code in the main form's
module. Me. or Me! is sufficient. So the syntax is:

Me!SubformControlName.Form!ControlName
This should work if CIT SubForm is the name of the subform control. If it
is not, change it to the name of the subform control.

If Me!TransApproval.Value = 1 Then
Me.[CIT SubForm.Form].txtCITAppr ="Yes"
Else
Me.[CIT SubForm.Form].txtCITAppr ="No"
End If
 
D

Debbiedo

There are a few problems.  First, you really should not use spaces in names.  
But, if you must, you have to enclose the name in brackets so Access will
understand them.
You don't need the : after the Else.  That is only when you are doing in In
Line If statemet.

Also you need to be clear on subforms and how they work.  What is unclear is
whether CIT SubForm is the name of the form being used as a subform or itis
the name of the subform control on the main form.  You do not use the name of
the form being used as a subform, you use the name of the subform controlon
the main form.  The actual form name is only used in the Source Object
property of the subform control so it knows what form to load as a subform.  
You have to use the word Form between the name of the subform control because
Form is the name used to reference the form that is the source object of the
subform control.  Then you use the name of the control on the form being used
as a subform.
You don't have to use the full qualifier since the code in the main form's
module.  Me. or Me! is sufficient.  So the syntax is:

Me!SubformControlName.Form!ControlName
This should work if CIT SubForm is the name of the subform control.  Ifit
is not, change it to the name of the subform control.

    If Me!TransApproval.Value = 1 Then
        Me.[CIT SubForm.Form].txtCITAppr ="Yes"
    Else
        Me.[CIT SubForm.Form].txtCITAppr ="No"
    End If

--
Dave Hargis, Microsoft Access MVP



Debbiedo said:
I have a main form called CIT Data Entry Form
I have a subform called CIT SubForm
TransApproval.Value is an option button in my main form
txtCITAppr has a control source in the subform that is a yes/no format
in its associated table
I want to say that if TransApproval.Value  = 1 , then txtCITAppr = Yes
else txtTransAppr = No.
I can't seem to get the syntax right. Ideas anyone?
Here is my latest feeble atttempt.
Forms.("CIT Data Entry Form").CIT SubForm.txtCITAppr ="Yes"

Forms.("CIT Data Entry Form").CIT SubForm.txtCITAppr ="No"
End If- Hide quoted text -

- Show quoted text -

I finally got it to work. It ended up being that even though the
control name on my subform was CIT SubForm, the application put an
underscore where the space was(CIT_SubForm). I would not have figured
this out if I hadn't looked at the autofill feature in the code
builder. I appreciate the code and clarification.

Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top