Board index » delphi » Master - Detail table relationships

Master - Detail table relationships

Hi there!

I have two tables that I have stored in my data module; table1 being the
master and table2 being the detail linked to the master via the MasterSource
& MasterFields properties in table2.  When I open a specific form that uses
both these tables, the master - detail relationship holds up and only
records in table2 that are related to the record in table1 show up in a
grid.  However, when I close the form and reopen it (no intermediate steps),
the relationship doesn't seem to be working.  All the records in table2 are
displayed in that grid.

What is going on here?  Am I doing something wrong?  Do I need to set a
property every time to refresh the relationship?

TIA,
Pam

 

Re:Master - Detail table relationships


I'll make sure that I reopen the tables in the right order.  In the meantime
though, I found out that this problem only happens on the first record.  If
I move to record #2 or higher, close the form, and reopen it, the record it
closed at shows up with no extra data (I've set a global variable to do
remember which record it was on) .

So very confusing...

Thanks!
Pam

"Alfred ten Hoeve" <alfred.tenHo...@freeler.nl> wrote in message
news:3ac8f6fc_1@dnews...

Quote
> Don't know what's going on. Is your mastertable closed when you close your
> form?
> A workaround could be that you close and reopen the tables (in the right
> order) in the form's OnShow event.

> Alfred.

> "Pam" <parke...@zdnetonebox.com> schreef in bericht
> news:3ac8cc7c$1_2@dnews...
> > Hi there!

> > I have two tables that I have stored in my data module; table1 being the
> > master and table2 being the detail linked to the master via the
> MasterSource
> > & MasterFields properties in table2.  When I open a specific form that
> uses
> > both these tables, the master - detail relationship holds up and only
> > records in table2 that are related to the record in table1 show up in a
> > grid.  However, when I close the form and reopen it (no intermediate
> steps),
> > the relationship doesn't seem to be working.  All the records in table2
> are
> > displayed in that grid.

> > What is going on here?  Am I doing something wrong?  Do I need to set a
> > property every time to refresh the relationship?

> > TIA,
> > Pam

Re:Master - Detail table relationships


Don't know what's going on. Is your mastertable closed when you close your
form?
A workaround could be that you close and reopen the tables (in the right
order) in the form's OnShow event.

Alfred.

"Pam" <parke...@zdnetonebox.com> schreef in bericht
news:3ac8cc7c$1_2@dnews...

Quote
> Hi there!

> I have two tables that I have stored in my data module; table1 being the
> master and table2 being the detail linked to the master via the
MasterSource
> & MasterFields properties in table2.  When I open a specific form that
uses
> both these tables, the master - detail relationship holds up and only
> records in table2 that are related to the record in table1 show up in a
> grid.  However, when I close the form and reopen it (no intermediate
steps),
> the relationship doesn't seem to be working.  All the records in table2
are
> displayed in that grid.

> What is going on here?  Am I doing something wrong?  Do I need to set a
> property every time to refresh the relationship?

> TIA,
> Pam

Re:Master - Detail table relationships


What database are you using? Are the tables closed at design time and opened
in code at runtime? Do you open the master first then the detail? I have
never seen or heard of the problem you describe so the more information you
can provide the better.

--
Bill

Re:Master - Detail table relationships


OK I've done a little more testing and found out that if I comment out the
detail.active := false in the OnClose event of the Close button, it works
just fine.

But why?
And why did it work before (prior to commenting out that line of code) for
records 2+?

Any insight would be greatly appreciated.

Thanks,
Pam

Quote
"Pam" <parke...@zdnetonebox.com> wrote in message news:3ac95070_1@dnews...
> I am using SQL Server 7.0.  All of the tables are closed at design time
and
> only opened when a specific form needs it. When I open a form the first
time
> and the first record is displayed, all is well.  If I close it and reopen
> it, all of the detail records show for that first record.  However, if I
> open the form the first time and scroll to record #6, for example, then
> close it, then reopen it, only the related records show in the detail
> section - which is what it's supposed to do.

> I have a master table appropriately called master and a couple detail
> tables, one called schhist.  They are linked together by the student's
SSN.
> This SSN is stored in a global variable so whichever form is opened, the
> same SSN remains the current record shown.

> I've tried commenting out certain lines of code, but nothing seems to
work.
> In the FormActivate event, I open the master first, then the detail.  In
the
> OnClose event, I close the detail first, then the Master.

> I think that's all there is to it; it really should be quite simple.  I'm
> not sure where I've gone wrong.  Any help would be greatly appreciated.

> Thanks,
> Pam

> "Bill Todd (TeamB)" <billtodd...@nospam.qwest.net> wrote in message
> news:3ac908f9$1_1@dnews...
> > What database are you using? Are the tables closed at design time and
> opened
> > in code at runtime? Do you open the master first then the detail? I have
> > never seen or heard of the problem you describe so the more information
> you
> > can provide the better.

> > --
> > Bill

Re:Master - Detail table relationships


I am using SQL Server 7.0.  All of the tables are closed at design time and
only opened when a specific form needs it. When I open a form the first time
and the first record is displayed, all is well.  If I close it and reopen
it, all of the detail records show for that first record.  However, if I
open the form the first time and scroll to record #6, for example, then
close it, then reopen it, only the related records show in the detail
section - which is what it's supposed to do.

I have a master table appropriately called master and a couple detail
tables, one called schhist.  They are linked together by the student's SSN.
This SSN is stored in a global variable so whichever form is opened, the
same SSN remains the current record shown.

I've tried commenting out certain lines of code, but nothing seems to work.
In the FormActivate event, I open the master first, then the detail.  In the
OnClose event, I close the detail first, then the Master.

I think that's all there is to it; it really should be quite simple.  I'm
not sure where I've gone wrong.  Any help would be greatly appreciated.

Thanks,
Pam

"Bill Todd (TeamB)" <billtodd...@nospam.qwest.net> wrote in message
news:3ac908f9$1_1@dnews...

Quote
> What database are you using? Are the tables closed at design time and
opened
> in code at runtime? Do you open the master first then the detail? I have
> never seen or heard of the problem you describe so the more information
you
> can provide the better.

> --
> Bill

Re:Master - Detail table relationships


OK I've done a little more testing and found out that if I comment out the
detail.active := false line in the OnClick event of the Close button, it
works
just fine.

But why?
And why did it work before (prior to commenting out that line of code) for
records 2+?

Any insight would be greatly appreciated.

Thanks,
Pam

Quote
"Pam" <parke...@zdnetonebox.com> wrote in message news:3ac95070_1@dnews...
> I am using SQL Server 7.0.  All of the tables are closed at design time
and
> only opened when a specific form needs it. When I open a form the first
time
> and the first record is displayed, all is well.  If I close it and reopen
> it, all of the detail records show for that first record.  However, if I
> open the form the first time and scroll to record #6, for example, then
> close it, then reopen it, only the related records show in the detail
> section - which is what it's supposed to do.

> I have a master table appropriately called master and a couple detail
> tables, one called schhist.  They are linked together by the student's
SSN.
> This SSN is stored in a global variable so whichever form is opened, the
> same SSN remains the current record shown.

> I've tried commenting out certain lines of code, but nothing seems to
work.
> In the FormActivate event, I open the master first, then the detail.  In
the
> OnClose event, I close the detail first, then the Master.

> I think that's all there is to it; it really should be quite simple.  I'm
> not sure where I've gone wrong.  Any help would be greatly appreciated.

> Thanks,
> Pam

> "Bill Todd (TeamB)" <billtodd...@nospam.qwest.net> wrote in message
> news:3ac908f9$1_1@dnews...
> > What database are you using? Are the tables closed at design time and
> opened
> > in code at runtime? Do you open the master first then the detail? I have
> > never seen or heard of the problem you describe so the more information
> you
> > can provide the better.

> > --
> > Bill

Re:Master - Detail table relationships


My best guess is that it is something in your code. You could set up a test
application with no code and see if you can reproduce the problem or you
could set a breakpoint on the close statement and trace into every function
that is executed to see what is happening.

--
Bill

Re:Master - Detail table relationships


Here's an update:

Instead of using the table and data source components in my data module, I
created new ones just for that specific form.  (BTW I don't know if it
matters or not, but I'm using ADOTable components, not TTable components).
I then changed all references in my code from the data module table/ds to
the local copy of them and ran the app.  It worked!  I looked at the
properties of the two table components (local and data module) and they were
exactly the same.

So, even though I found a work-around, I still haven't discovered the
reason.

Thanks for all your help!

Pam

"Bill Todd (TeamB)" <billtodd...@nospam.qwest.net> wrote in message
news:3aca0aa5$1_1@dnews...

Quote
> My best guess is that it is something in your code. You could set up a
test
> application with no code and see if you can reproduce the problem or you
> could set a breakpoint on the close statement and trace into every
function
> that is executed to see what is happening.

> --
> Bill

Other Threads