Link to home
Start Free TrialLog in
Avatar of htamraz1
htamraz1Flag for United States of America

asked on

Synchronizing two subforms in MS Access

I have two subforms that I am trying to synchronize and it's not happening. I am wondering if you could help please.

Subform 1 is called frmCampaignsSub (continuous form)
Subform 2 is called frmCampaignsDetSub (single form)

The PK field CP_ID is common to both record sources

When a user clicks or selects a record in Subform 1, I want Subform 2 to show the details accordingly.

Here are my link settings in Subform2 as they related to Subform 1:

Link Child Fields = cp_id
Link Master Fields = Forms!frmMain!frmCampaignsSub.Form!cp_id

So far, Subform 2 is synchronizing ONLY with the first record/row of Subform 1. However, if I move from record to record on Subform 1, Subform 2 is not synchronizing.

Any clues? I would appreciate you nailing any coding syntax using the field and key values I provide in my text.

Thank you.
Avatar of adraughn
adraughn
Flag of United States of America image

you need to requery the subform
Avatar of htamraz1

ASKER

I tried. Not working. Have some syntax in mind?

Parent form = frmMain
Subform 2 (the one to requery) = frmCampaignsDetSub

I am assuming I need to initiate the requery from Subform 1. Right?

I tried doing this on the Current Event as follows:

forms!frmMain!frmCampaignsDetSub.Requery

Did NOT work!!!

how are your users navigating thru records? add this to the click event for the button:

me.subformname.requery
putting this on the current event should work though:

[SubformName].Requery
It seems logical, but I get an error

Object required (Error 424)

I used SubformName].Requery as follows:

[frmCampaignsDetSub].Requery

To answer your other questions, users will be scrolling down a continue form in Subform 1 and as they hit each row, Subform 2 should synchronize according.
me.[frmCampaignsDetSub].Requery
Avatar of Rey Obrero (Capricorn1)
if the setting for the master/child links are correct, no need for the requery.
check the record source of the subforms.

also, what is the set up?

both subform in main form
Main form
   subform1
   subform2

or subform2 in subform1
Main form
   subform1
        subform2

Subform is continuous, which may not have a subform.  That, I expect, is the problem.  The the child is not a subform of the master.
capricorn1

It is the former example

both subform in main form
Main form
   subform1
   subform2
adraughn

Your last suggestion did not work...Please keep in mind what I noted to capricon1 about setup. You are referencing subform2 from subform1 using 'Me', which it did not understand because the subform2 object lives outside subform1.

both subform in main form
Main form
   subform1
   subform2
what about the record source of the subforms?
dqmq

I understand your logic here, but why should this limit my scenario. The two subforms have related records that are tied by CP_ID. All I want to do is to select a campaing from this continuous form (i.e. Subform 1) and have the corresponding details for the campaign show in Subform 2. I assumed their common link CP_ID would do the trick and it does indeed, but only for the 1st record of Subform 1. As I go down my continuous Subform 1, I want the corresponding detail to show in Subform 2.

capricorn1,

The record source of the subforms is a SQL query both queries have CP_ID, which is a unique identifier.

I am not sure if I answered your question?


Capricorn1

I wanted to clarify the following further

both subform in main form
Main form
   subform1 (this is a continuous form)
   subform2 (single view form)
check this thing too.

in design view of frmMain
click on the outer edge of subform1 hit F4
click on the Data tab  check take note of what is on Source Object
click on the Other tab, is the Name the same as the one in the Source Object?

do the same thing for subform2
ASKER CERTIFIED SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it is possible to link two unbound subforms in ms access. see below.


create a new form
insert a text box -- name it "txtLink"
on the form insert two sub-forms

lets name them: subformA  and subformB


subformA will be your "main" display while subformB will contain a list of the records with a brief description/pic.

(make sure you set the control sources to your subforms)
also set subformB to be a continuous form. subformA should be set at single view

ok this gets a little hairy--

right click on the text box you created - set the control source to one of the fields in subformB (for example the ID/autogen number field.) use one that has unique data.
(use the expression builder to do this) it will end up being something like
=me.subformB!forms![yourfield]

after you have done that you will know you did it right if when you click on a record in subformB the text/number in your textbox will change.

now go to the properties of subformA
here we will set the parent and child fields.         *(do not set these in subformB)

you have to type these in manually if you click on the "..." in the fields an error will come up saying you cant do it.

in the parent block type in the name of your textbox we made earlier.   "txtLink"
the data has to match so
because the "txtlink" controlsource is set to the ID field in subformB
the child block should be the id field in subformA  which should be something like "ID"

following these steps will make you able to link two "unbound forms" and when you click on a record in subfromB subformA will goto that record.


i hope that wasn't too much info let me know if you need clarity. i hope this isn't as clear as mudd. i do not have access to ms access on this computer but i will be at work in the morning and if you need i can clarify.

hope this helps

good luck
this works!!!!!!  this is what you are looking for


create a new form
insert a text box -- name it "txtLink"
on the form insert two sub-forms

lets name them: subformA  and subformB


subformA will be your "main" display while subformB will contain a list of the records with a brief description/pic.

(make sure you set the control sources to your subforms)
also set subformB to be a continuous form. subformA should be set at single view

ok this gets a little hairy--

right click on the text box you created - set the control source to one of the fields in subformB (for example the ID/autogen number field.) use one that has unique data.
(use the expression builder to do this) it will end up being something like
=me.subformB!forms![yourfield]

after you have done that you will know you did it right if when you click on a record in subformB the text/number in your textbox will change.

now go to the properties of subformA
here we will set the parent and child fields.         *(do not set these in subformB)

you have to type these in manually if you click on the "..." in the fields an error will come up saying you cant do it.

in the parent block type in the name of your textbox we made earlier.   "txtLink"
the data has to match so
because the "txtlink" controlsource is set to the ID field in subformB
the child block should be the id field in subformA  which should be something like "ID"

following these steps will make you able to link two "unbound forms" and when you click on a record in subfromB subformA will goto that record.


i hope that wasnt too much info let me know if you need clarity. i hope this isnt as clear as mudd. i do not have access to ms access on this computer but i will be at work in the morning and if you need i can clarify.

hope this helps

good luck