Change LinkChildField and LinkMasterField for a form/subform

G

Guest

In my previous question, I asked how to set the RecordSource property for a
subform. Having got this right, I now want to filter (for a date) for one
RecordSource, but not the the other. I have a button which switches between
two RecordSources, one I want date filtered, one I don't.

So I want to set the LinkChildField and LinkMasterField properties for the
subform to field [Date] (both fields are called [Date]) in the first instance
and to Null in the second.

Using SetValue:

forms!Form!SubForm.Form.LinkChildField = "Data"

Returns error "Can't find the field 'LinkChildField' referred to in your
expression.

As I spelling LinkChildField incorrectly or is there something else? I
obviously need to do the same for LinkMasterField.
 
D

Dirk Goldgar

In
Rod Behr said:
In my previous question, I asked how to set the RecordSource property
for a subform. Having got this right, I now want to filter (for a
date) for one RecordSource, but not the the other. I have a button
which switches between two RecordSources, one I want date filtered,
one I don't.

So I want to set the LinkChildField and LinkMasterField properties
for the subform to field [Date] (both fields are called [Date]) in
the first instance and to Null in the second.

Using SetValue:

forms!Form!SubForm.Form.LinkChildField = "Data"

Returns error "Can't find the field 'LinkChildField' referred to in
your expression.

As I spelling LinkChildField incorrectly or is there something else? I
obviously need to do the same for LinkMasterField.

The names of the properties are:

LinkChildFields
LinkMasterFields

Note the trailing "s".
 
D

Douglas J. Steele

The two Link fields are properties of the subform control, not of the form
being used as a subform.

That means you just need

Forms!Form!SubForm.LinkChildField = "Data"

One thing I will caution you of is that depending on how to add the form as
a subform to the parent form, the name of the subform control on the parent
form may not be the same as the name of the form being used as a subform.
You need to ensure that you use the name of the subform control.
 
G

Guest

A typo here, not in my code, sorry.

I have used SetValue to set:

[Forms]![Central]![Form Requirements subform].[Form].[LinkChildFields] =
"Date"
and
[Forms]![Central]![Form Requirements subform].[Form].[LinkChildFields] = Null

The brackets around LinkChildFields are entered automatically by Access. I
get the error message:

"Can't find the field 'LinkChildFields' referred to in your expression."
 
G

Guest

Thanks, Douglas. My syntax was incorrect
(Forms!Form!Subform.Form.LinkChildFields should be
Forms!Form!Subform.LinkChildFields).

Douglas J. Steele said:
The two Link fields are properties of the subform control, not of the form
being used as a subform.

That means you just need

Forms!Form!SubForm.LinkChildField = "Data"

One thing I will caution you of is that depending on how to add the form as
a subform to the parent form, the name of the subform control on the parent
form may not be the same as the name of the form being used as a subform.
You need to ensure that you use the name of the subform control.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Rod Behr said:
In my previous question, I asked how to set the RecordSource property for
a
subform. Having got this right, I now want to filter (for a date) for one
RecordSource, but not the the other. I have a button which switches
between
two RecordSources, one I want date filtered, one I don't.

So I want to set the LinkChildField and LinkMasterField properties for the
subform to field [Date] (both fields are called [Date]) in the first
instance
and to Null in the second.

Using SetValue:

forms!Form!SubForm.Form.LinkChildField = "Data"

Returns error "Can't find the field 'LinkChildField' referred to in your
expression.

As I spelling LinkChildField incorrectly or is there something else? I
obviously need to do the same for LinkMasterField.
 
D

Dirk Goldgar

In
Rod Behr said:
A typo here, not in my code, sorry.

I have used SetValue to set:

[Forms]![Central]![Form Requirements
subform].[Form].[LinkChildFields] = "Date"
and
[Forms]![Central]![Form Requirements
subform].[Form].[LinkChildFields] = Null

The brackets around LinkChildFields are entered automatically by
Access. I get the error message:

"Can't find the field 'LinkChildFields' referred to in your
expression."

The LinkMasterFields and LinkChildFields are properties of the subform
control (on the main form), not of the subform control's Source Object.
So your references need to be:

[Forms]![Central]![Form Requirements subform].[LinkChildFields]
[Forms]![Central]![Form Requirements subform].[LinkMasterFields]
 

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