How can I link form/subform in code?

  • Thread starter Thread starter DanJ
  • Start date Start date
D

DanJ

I have a Main form with a subform which I want to set the Master/Child
property for in code. In the Main forms Open event I have the following:

Me.Jail_Record_Act_Log.LinkMasterFields = "Jail_ID"
Me.Jail_Record_Act_Log.LinkChildFields = "Jail_ID"

Jail_ID is a long integer field and the control is the same name as the
field. Jail_ID is Primary Key for the recordsource of the main form and a
foreign key for the recordsource of the subform.

Jail_Record_Act_Log is the name of the subform control which holds the
subform of the same name.

When I open the main form I get the following error:

Run-time error '2101':
The setting you entered isn't valid for this property.

I experimented by manually adding the Jail_ID link in Design view and it
works fine if I save the form with the link already entered. But I want to
be able to change the link in code later.

I have also tried changing all the names so that the field name is different
than the control name and the subform name is different than the subform
control name.

Any ideas what is wrong?
 
DanJ said:
I have a Main form with a subform which I want to set the Master/Child
property for in code. In the Main forms Open event I have the following:

Me.Jail_Record_Act_Log.LinkMasterFields = "Jail_ID"
Me.Jail_Record_Act_Log.LinkChildFields = "Jail_ID"

Jail_ID is a long integer field and the control is the same name as the
field. Jail_ID is Primary Key for the recordsource of the main form and a
foreign key for the recordsource of the subform.

Jail_Record_Act_Log is the name of the subform control which holds the
subform of the same name.

When I open the main form I get the following error:

Run-time error '2101':
The setting you entered isn't valid for this property.

I experimented by manually adding the Jail_ID link in Design view and it
works fine if I save the form with the link already entered. But I want to
be able to change the link in code later.

I have also tried changing all the names so that the field name is different
than the control name and the subform name is different than the subform
control name.


This has always been a little tricky. The first thing I try
is setting the link child property first. If that doesn't
take care of it, then try setting both properties to a ZLS
(zero length string) before setting them to the desired
field names.

Also make sure the link child property is a field name in
the subform's record source table/query.
 
Back
Top