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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove LinkChildFields problem 1

Status
Not open for further replies.

GPM4663

Technical User
Aug 9, 2001
165
GB
Hi Everyone
I have a form with a subform which source object is dependant upon information the user enters. I have set the "Link Master Fields" property to the correct control in the main form and then I use the following code to display the subform

Me.subformCard.SourceObject = "subFormJobCard"
Me.subformCard.LinkChildFields = "JobCardRef"
me.subformCard.visible = true

it all works well except if I clear the values on the screen and try to go to the other sourceobject. It asks me for a parameter value based on what I had previously entered. I have tried using a "Clear" button that runs the code:

Me.subformCard.SourceObject = ""
Me.subformCard.LinkChildFields = ""

but it won't let me remove the linkChildFields value.

If I just click OK or cancel to the parameter value input box it still assigns the subform but this will be confusing for the users.

Also If I exit the form between inputs I don't have the problem but the interface needs to be worked by adding a value performaning an operation and then clearing the screen for the next user.

Does anyone have any ideas?

many thanks in advance,

GPM

 
Yes you should be able to change the source object and linked fields without any problem. It is difficult to tell where the problem is, but it sounds like an order of events issue. My first guess would be that the source object changes, an event fires, but the linked child field has not changed yet. Therefore you get a parameter looking for a field that does not exist in the underlying recordsource. I would try something like.

Me.subformCard.LinkChildFields = ""
Me.subformcard.linkMasterFields = ""
Me.subformCard.SourceObject = "new Source object"
doevents
Me.subformcard.linkMasterFields = "yourmasterfield"
Me.subformCard.LinkChildFields = "yournewchild
 
Hi MajP,
I've tried the code you suggested but on the first line I get the error "Run time error 2101 - the setting you entered isn't valid for this property" I've tried swapping the lines around but it still comes up with the error on the first line where I am trying to set the linkChildFields or LinkMasterFields = "".

Any other thoughts?

thanks

GPM
 
How are ya GPM . . .

If you can't get it to work during runtime, then you'll have to temporarily switch to design view to make the changes and reopen the form:
Code:
[blue]   [green]'Applicatio.Echo False 'Stop Screen Updates
   'DoEvents[/green]
   DoCmd.OpenForm "[purple][B][I]FormName[/I][/B][/purple]", acDesign, , , , acHidden
   [green][b]'Your link/source changes here[/b][/green]
   DoCmd.OpenForm "[purple][B][I]FormName[/I][/B][/purple]"
   Applicatio.Echo True 'Allow Screen Updates[/blue]
Do not activate the rem lines unless it works. Reason being ... [blue]Application.Echo[/blue] hides updates to the screen in an attempt to make the transition look smooth to the eye. If an error occurs while its turned off, it'll appears as if everything is locked. In any case code is currently untested.

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I am sorry, but you are doing something incorrect. There is no reason you should get
"Run time error 2101 - the setting you entered isn't valid for this property"
unless you have something else going on.

My description of the problem is correct. I was able to replicate your exact problem by switching the source object prior to switching the link child fields and link master fields. Once I switched the linked fields and then the source object there was no problem.

run a debug compile and ensure you have option explicit. This is one of the rare times I disagree with Ace Man. Going into design view is putting a band aid on the symptom not fixing the cause.



 
Hi Guys,
Thanks for all the input I really appreciate it but I've figured out the problem. I thought I was getting the error because I still had a sequence problem but I realised that when I was stepping through the debugger that the linkchildfields had the value "" before the line to set it to "" had been executed.

I suddenly realised that for some reason it doesn't like you setting the Me.subformCard.LinkChildFields = "" if it is already set to "". I had been trying to run the "Clear Links" function to "" before actually setting it to a proper value in an attempt to trap the error. I've sorted it out with a simple "if" command.

It shows the danger of only running part of your code at a time when hunting a problem.

Thanks again for all the help, it certainly gave me something to think about.

Cheers,

GPM
 
There is actually no reason to have to "clear" the link fields to "" prior to assigning the real value. Again, as long as you change the link fields prior to assigning the source object it should work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top