Help with linking a Subform to another subform

  • Thread starter Thread starter leem888
  • Start date Start date
L

leem888

I'm hoping someone will be able to help me.

I have a master/detail form that works fine. The detail is in a
datasheet view and shows about four columns of a 100 column table.
I've created another form that contains the remainder of the fields
from the table.

What I am trying to do is that when someone clicks or sets focus to a
particular record in the datasheet subform, the second subform with all
of the other fields shows the record information for the row that has
focus.

I do not have enough experience to know which expression/method to use
or if there is a simpler way of accomplishing this task.

Can anyone help???

Michael Lee
 
I have a master/detail form that works fine. The detail is in a
datasheet view and shows about four columns of a 100 column table.
I've created another form that contains the remainder of the fields
from the table.

What I am trying to do is that when someone clicks or sets focus to a
particular record in the datasheet subform, the second subform with all
of the other fields shows the record information for the row that has
focus.


Use the datasheet subform's Current event to set a main form
hidden text box to the subform's primary key field.

Me.Parent.hiddentextbox = Me.pkfield

Then set the other subform's Link Master Fields property to
the hidden text box and the Link Child Fields property to
the primary key field.
 
Marsh -

Thanks for the help thus far.

Unfortunately, I may need more help than what you have suggested. I'm
afraid I'm a little confused by the hiddentextbox reference. This
maybe why... My master form is associated by eventID, my subform1 is
associated to the master by eventID. I have ID for the subform1
visible and ID for subform2 visible as well. I'm trying to associate
the datasheet from subform1 to the single view of subform2.

Based on your suggestion here is what I have. This code is placed in
the currect event of subform1

Private Sub Form_Current()
Me.Parent.hiddentextbox = Me.ID
End Sub

and under the Data tab for the subform2 I have

Link Child Fields = ID
Link Master Fiedls = ID

Of course I keep getting prompted for the ID and I keep getting and
error message for the "hiddentextbox" reference.

Any additional suggestions?
 
Unfortunately, I may need more help than what you have suggested. I'm
afraid I'm a little confused by the hiddentextbox reference. This
maybe why... My master form is associated by eventID, my subform1 is
associated to the master by eventID. I have ID for the subform1
visible and ID for subform2 visible as well. I'm trying to associate
the datasheet from subform1 to the single view of subform2.

Based on your suggestion here is what I have. This code is placed in
the currect event of subform1

Private Sub Form_Current()
Me.Parent.hiddentextbox = Me.ID
End Sub

and under the Data tab for the subform2 I have

Link Child Fields = ID
Link Master Fiedls = ID

Of course I keep getting prompted for the ID and I keep getting and
error message for the "hiddentextbox" reference.


You need to add a new text box to the main form.

Let's name this new text box txtLinker. Set its Visible
property to No to hide it so it doesn't get in the way.

subform1's Current event would then be:
Private Sub Form_Current()
Me.Parent.txtLinker = Me.ID
End Sub

Then set subform2 control's properties:
Link Master: txtLinker
Link Child: ID

On second thought. I'm not sure that you're telling me that
the subforms' record source table's primary key is ID. It
sounds more like its a foreign key link to the main form
table's primary key. If this is the case, replace ID in the
two places above with the name of the subform table's
primary key.
 
I'm probably not communicating it properly. There are two tables
involved: event(eventID, eventName, eventYear) -
eventRestaurantLink(ID, eventID, restaurantID, 100 additional
fields...)

so the main form has the event fields
subform1 has four fields from eventRestaurantLink (with ID being
primary key)
subform2 has the remaining fields from eventRestaurantLink (with ID
being primary key)

so ultimately there are three forms on the screen, the master/detail
(subform1) and below that subform2

I changed a couple of things to correspond with your suggestions, but I
keep getting the same errors.

Am I confusing the topic??? Let me know how I can either post the db
or email it to you.

Michael Lee
 
I'm probably not communicating it properly. There are two tables
involved: event(eventID, eventName, eventYear) -
eventRestaurantLink(ID, eventID, restaurantID, 100 additional
fields...)

so the main form has the event fields
subform1 has four fields from eventRestaurantLink (with ID being
primary key)
subform2 has the remaining fields from eventRestaurantLink (with ID
being primary key)

so ultimately there are three forms on the screen, the master/detail
(subform1) and below that subform2

I changed a couple of things to correspond with your suggestions, but I
keep getting the same errors.

Am I confusing the topic??? Let me know how I can either post the db
or email it to you.


That appears to clarify things, not confuse them. Actually,
that what I first thought you were saying before I confused
myself with second thoughts.

If you carefully followed my instructions in my previous
post, then it should work. What errors do you get?
 
The error message displayed is:

Run-time error '2465'

Applicaiton-defined or object-defined error.

Thank you again for all you insight and help.
 
The error message displayed is:

Run-time error '2465'

Applicaiton-defined or object-defined error.


Well, that is a singularly uninformative error message. Can
you provide more information? A Copy of your current code,
text box name, link Master/Child properties and if at all
possible which line had the error might be helpful.
 
ok... first, in the main form, i created the hidden text box and made
the name "txtLinker". (I'm with this one because I cannot assign the
ID to this field because the main form is associated with the event
table that only has an eventID in that table.

second, in subform1, in the event tab using the on_current event i have
the following code.

Private Sub Form_Current()
Me.Parent.textLinker = Me.ID
End Sub

third, in subform2, in the data tab, i have the following set for the
two parameters:

Link Child Fields = ID
Link Master Fields = txtLinker

I'm using MS Access 2003 on a Windows XP Professional OS. I hope this
gives you more to work with... again, is there a way I can post the DB
for you to pull down?
 
ok... first, in the main form, i created the hidden text box and made
the name "txtLinker". (I'm with this one because I cannot assign the
ID to this field because the main form is associated with the event
table that only has an eventID in that table.

second, in subform1, in the event tab using the on_current event i have
the following code.

Private Sub Form_Current()
Me.Parent.textLinker = Me.ID
End Sub

third, in subform2, in the data tab, i have the following set for the
two parameters:

Link Child Fields = ID
Link Master Fields = txtLinker

I'm using MS Access 2003 on a Windows XP Professional OS. I hope this
gives you more to work with... again, is there a way I can post the DB
for you to pull down?


You mispelled txtLinker in the subform's Current event
procedure.

Is that the line that generates the error message?

How did you ever get the code to compile with that mistake
in it?
 
SUCCESS!!! I double checked the mispelling and that was the issue. So
it works. I cannot believe it was such a simple mistake.

Thank you again.

Michael Lee
 
Back
Top