PDA

View Full Version : Control and lonk two subforms



mud2
09-08-2008, 06:13 PM
Here I Try again: One main form with two subforms, child1 and child2. The main form has a combox connected to a table of table and form names. Child1 contains Record navigation buttons and child2 (will) contain a form that will show/accept data. Both child forms get thier Sourceobject and record source from the combobox. There will be several data forms.
Problem: How to link the two subform so that the navigation form navigates the data form?

CreganTur
09-09-2008, 09:41 AM
Question... why are you using a subform to create navigation buttons for another subform? Subforms have their own navigation buttons built in. And if you don't like them, you can always hide them and use actual buttons in the subform's header(or footer based on preference) to create custom navigation buttons that are "linked" to that subform... they're inoperative until you use a little VBA... but there you go.

Having a subform just for the sake of creating navigation buttons seems very sub-optimal because it adds another level of complexity (having to deal with yet another subform) that you don't really need.

I can see what you're trying to accomplish: having a main "viewer" Form from which other forms can be activated and used... but does this add any value over actually opening the other Forms, or is it a style choice?

mud2
09-09-2008, 11:01 AM
Thank you Mr. Tur. I've already reached one of your suggestions: Navigation buttons ARE now part of the main form. I copy this form and modify the copy to have ONE subform, whose SourceObject is set by a conbo box in the main form. Now I must "link" the navigation buttons to the particular subform i've called up.Why?
Stubborness?
There will be many data forms with different formats, but all will need navigation. I will limit navigation and record opertions (edit, add, delete...) depending on the user's choice. this results in complicated programming, which I'd like to set one time only, under the navigation part of the form.
As a final "solution", I could copy the main form for EACH subform...and not use subforms at all!

CreganTur
09-09-2008, 11:58 AM
Mr. Tur
:giggle never been called that before. You can call me Randy... or if you prefer to use handles rather than real names, then call me Cregan.


There will be many data forms with different formats, but all will need navigation. I will limit navigation and record opertions (edit, add, delete...) depending on the user's choice. this results in complicated programming, which I'd like to set one time only, under the navigation part of the form.

Am I correct in assuming that the combobox allows the users to select the names of the forms they want to work with? The names that they select... do they match the actual names of the forms?

For setting up your navigation buttons- I'm guessing the issue you're running into is how to make them dynamic so the can work with whatever form is setup. If the combobox contains the actual form names, then can you not reference the value of the combobox and use that in the code to 'link' your navigation buttons to the selected subform?

If your combobox doesn't contain the actual names, then you could add them in easily by using a list. Have the combobox use 2 columns- the first column would be the actual form name, and the second column would be the form name for the user. Set the column width of the first column to 0" to hide it from view. Then, when you reference the combobox's value it will pull the value of the first column.

HTH:thumb

mud2
09-09-2008, 02:57 PM
OK, "Raandy":
I have discovered the joys of the combo box, through combo.columns() My unbound Table names are in column(0), and corresponding Form names in column(1)
My unbound main form contains a combo box, a set of navigation buttons(controls), and an unbound child form. The Main Forms RecordSource is set by:
"Me.form.RecordSource = Me.combo6(column(0)" The child's sourceobject is set by "Me.Child14.SourceObject = Me.combo6.column(1)" This all works..except that the child's navigation buttons do not work, and the main forms control and navigation buttons do not affect the records shown in the chosen child form.

mud2
09-09-2008, 08:36 PM
A note on the above priblem that the child nav. buttons don't work: Set the child.scrollbars = 0 (neither), then they do work, but STILL are not synchronized withy the master navigation buttobs!

mud2
09-09-2008, 10:34 PM
Private Sub Combo6_Click()
Me.Form.RecordSource = Me.Combo6.Column(0) ' Works, Column(0) is Table name
Me.Child14.SourceObject = Combo6.Column(1) ' Column(1) is Form Name
'Me.Child14.Form.ScrollBars = 0 'needed if want to use record selectors in Child forms!
" Following work, but refer to "Absolute" field names
'Child14.LinkChildFields = "Name" ' These work
'Child14.LinkMasterFields = "Name" ' These work!
' Following more general
With Child14
.LinkChildFields = Child14.Controls.Item(0).Name ' These more general!
.LinkMasterFields = Child14.Controls.Item(0).Name ' " "
.Form.NavigationButtons = False ' "
.Form.ScrollBars = 0 ' "
End With
End Sub

Works, "Except" when going to a New record, get a message asking for a parameter.

mud2
09-11-2008, 09:51 AM
OK, I give up! Dammed ACCESS knows what you want to do and hides(useless) tips under rocks in diverse forests! The above "Solution" was a quirk...works sometimes and not others! annot add a new record.

CreganTur
09-11-2008, 10:49 AM
Instead of adding a new record through your subform, you could create an Add Record button (on either the subform or main form) that would open up a data entry form. It does break up your form's functionality, but it will leave you with a working viewer, and give your users the ability to add new records.

This means you might have to make a lot of data entry forms... but if it works, it works!

mud2
09-11-2008, 12:38 PM
Randy: Yes, if it works...it works! I've used this (Multi data forms) method and it does work. What i've been trying is more elegant..or would be more elegant.
Thanks!

mud2
09-11-2008, 08:32 PM
To Link a main form to any of a number of child forms. This is ONE way:
1. In underlying tables, set up an autonumbering field...call it MyKey.
2. In main form and EACH subform set up a text field..named, and with source = MyKey.
3. In the main form, Object view, click on the child form. Click on Properties, data.
LinkChildFields MyKey
Link masterFields MyKey
Note the above cannot be done in the programming in the main form...

Hallaluyah! It works! After two months of struggling!
The text boxes MyKey can be set visible = False.

Credit to stubbornness, AND to Microsoft Office ACCESS 2003 Bible, Prague et.al., pp. 515. A SIMPLE, unadorned explaination!

mud2
09-12-2008, 04:09 PM
My last "Solution" works, but is too complicated! The extra field "MyKey" in the forms is NOT Needed! Just have a column in the underlying table to refer to...no need to put it on a dorm!

mud2
09-13-2008, 07:09 PM
So my Final solution worked..on the surface! But when I went to "ADD", and a new, empty record showed, and I typed in the first character in any of the fields, an error message "You tried to use a null...Redimension as a varient..."
So Access let me have at least two nights sleep before springing its latest "Gotcha" on me. I wil now follow Randy's suggestion, and have many forms, each with its own navigation buttons. No more "Elegence"!