Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Link fields dynamically when number of link fields changes

Status
Not open for further replies.

kathryn

Programmer
Apr 13, 2000
776
0
0
US
Good morning, all. Long time no post.

I am helping a coworker with a project. He needs to change the linking
fields of a subform in code. The problem is that in certain circumstances,
there will be one field to link the form/subform and in other fields there
will be two fields.

What happens is:

If the link is set to two fields and we try to change it to link on one,
when we change the first link (either the LinkChildFields or
LinkMasterFields property) then the number of fields don't match, and we
get an error.

How do I get around this problem?

Here is the code:

****BEGIN CODE****

If Me.OpenArgs = 0 Then
Me!txtLastName.Visible = True
Me![FromOffice].Visible = False
Me!FromCustId.Visible = False
Me!FromAccount.Visible = False
Me![frmShowRecordsSubForm].LinkChildFields = "lastname"
Me![frmShowRecordsSubForm].LinkMasterFields = "lastname"
ElseIf Me.OpenArgs = 1 Then
Me![FromOffice].Visible = True
Me!txtLastName.Visible = False
Me!FromAccount.Visible = False
Me!FromCustId.Visible = True
Me![frmShowRecordsSubForm].LinkChildFields = "fromoffice;fromcustid" 'ERROR HERE
Me![frmShowRecordsSubForm].LinkMasterFields = "fromoffice;fromcustid"
Else
Me![FromOffice].Visible = True
Me!txtLastName.Visible = False
Me!FromAccount.Visible = True
Me!FromCustId.Visible = False
Me![frmShowRecordsSubForm].LinkChildFields = "fromoffice;fromaccount"
Me![frmShowRecordsSubForm].LinkMasterFields = "fromoffice;fromaccount"
end if

****END CODE


Thanks for any input, ideas, references.
Kathryn


 
Solved it myself. for archive purposes, here is the solution.

You need to set the linkchildfields and linkmasterfields properties to an empty string "" before resetting them.

For example:
Me![frmShowRecordsSubForm].LinkChildFields = ""
Me![frmShowRecordsSubForm].LinkMasterFields = ""
Me![frmShowRecordsSubForm].LinkChildFields = "lastname"
Me![frmShowRecordsSubForm].LinkMasterFields = "lastname"

Then it works Kathryn


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top