Link Child/Master run-time error 2335

I am trying to change the Child/Master links in the following manner:

Private Sub Frame23_AfterUpdate()
If Me.Frame23.value = 1 Then
 
  Me("sfrmpayhrs").LinkChildFields = "site_name ; weekno"
  Me("sfrmpayhrs").LinkMasterFields = "site_name ; weekno1"
  Me.sfrmPayHrs.Requery
 
ElseIf Me.Frame23.value = 2 Then

  Me("sfrmpayhrs").LinkChildFields = "site_name ; weekno"
  Me("sfrmpayhrs").LinkMasterFields = "site_name ; weekno2"
  Me.sfrmPayHrs.Requery

ElseIf Me.Frame23.value = 3 Then

  Me("sfrmpayhrs").LinkChildFields = "site_name"
  Me("sfrmpayhrs").LinkMasterFields = "site_name"
  Me.sfrmPayHrs.Requery

End If

End Sub

. . . when I update the control I get :

"run-time error 2335" "You must use the same number of fields when you set the LinkChildFields and LinkMasterFields properties"

How can I get this code to work?

(Acc 2002 Win 2000)

Thanks
LVL 9
tonydemarcoAsked:
Who is Participating?
 
OzzModCommented:
Closed, 500 points refunded.
OzzMod
Community Support Moderator (Graveyard shift)
0
 
squirrlCommented:
Is it possible to provide a little more detail?  Are we talking mainform/subform child master links?
0
 
tonydemarcoAuthor Commented:
squirrl,

Yes.
Frame23 is an option box on the main form that after update, resets the subform master/child relations.
I believe that the error occurs because the code tries to reset the links from two relations to one.


0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
squirrlCommented:
That makes sense.  If you have, for example, a 'Client'
form and subform, they might well be linked on ClientID.  If you let Access do the linking, via the form wizard, that is the sort of thing it comes up with.

squirrl.
0
 
squirrlCommented:
If you let me know why you want to change the link, it might help in arriving at a solution.  Might you be looking for a tabbed form perhaps?
0
 
tonydemarcoAuthor Commented:
Here is what I did to solve the problem.

In the data table I added a placeholder field with a value of one. Basically a dummy field.

Then I coded as follows:

Private Sub Frame23_AfterUpdate()
If Me.Frame23.value = 1 Then
  Me("sfrmPayHrs").LinkChildFields = "site_name ; weekno"
  Me("sfrmPayHrs").LinkMasterFields = "site_name ; weekno1"
  Me.sfrmPayHrs.Requery
 
ElseIf Me.Frame23.value = 2 Then
  Me("sfrmPayHrs").LinkChildFields = "site_name ; weekno"
  Me("sfrmPayHrs").LinkMasterFields = "site_name ; weekno2"
  Me.sfrmPayHrs.Requery

ElseIf Me.Frame23.value = 3 Then
  Me("sfrmPayHrs").LinkChildFields = "site_name ; placeholder"
  Me("sfrmPayHrs").LinkMasterFields = "site_name ; placeholder"
  Me.sfrmPayHrs.Requery
End If
End Sub

This establishes the same number (2) of links and the form works.

squirrl, thanks for your help.

0
 
MzLibertyCommented:
Thanks! You can actually just list the same link field twice when you only want the one field to link. Handy when switching between a filtered view and the entire dataset.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.