Relationship question or 2 - Forum

Forum Navigation
You need to log in to create posts and topics.

Relationship question or 2

This is a bit embarrassing at this point but I need to ask.

I have been using Neobook Db Pro for a long time.

One think I have not been clear on is Master-Detail Relationship and when/where to Define or End.

Can all Relationship be defined at startup?

Is there a need to Define and/or Cancel Relationship at points in the code of the program?

This was brought to my attention when I looked at some old code and I saw I did "EndRelationship' and 'DefineRelationship' in the same code segment.

 

 

@cssystems

I haven't studied it in detail. But maybe this help page will help?

 

It's not the reports.

It in the coding.

Can I create all the relationships at the beginning or will some conflict with each other.

Sample of my coding.  Do I need EndRelationship (because it might be used elsewhere?

And recreate 'Define Relationship' again ?

CustomWindow "Print Date Range" "-1" "-1" "PrintDates" "DialogBox+Exclusive"

IF "[OkStatus]" "=" ""
 dbpEndRelationship "AddrBook" "Contacts" "DuesPaid"
 dbpDefineRelationship "AddrBook" "DuesPaid" "MemNum" "Contacts" "MemNum" ""
 dbpSort "AddrBook" "DuesPaid" "DatePaid=ASC"

. If "[pFilter]" ">" ""
   dbpQuery "AddrBook" "DuesPaid" "DatePaid Between #[PFromDate]# and #[PToDate]#"
. EndIf

 dbpSetFieldProperties "AddrBook" "DuesPaid" "AmtPaid" "Alignment=Right;DisplayFormat=$#.00"

 dbpPreviewReport "AddrBook" "Payments Report2.dbr" "DisplayMode=100%;InitialPage=1"
 dbpEndRelationship "AddrBook" "DuesPaid" "Contacts"
 dbpDefineRelationship "AddrBook" "Contacts" "MemNum" "DuesPaid" "MemNum" ""

EndIf

 

 

You can define relationships all you want after the appropriate tables are open.

Here's a cursory review:
All related fields need the same data such as record ID number. When your master table has a particular record selected your detail table will "query" all records with that record ID. It's just like doing a query in your detail table. when you end the relationship, it's like ending a query with dbpShowAll.

I've never done it but I think theoretically you should be able to create a relationship using your detail table as a master to yet another table, and so on.

Master table: Widgets - Field: recID
Detail table: Color - Field: recID
Master Table: Color - Field: Scheme
Detail Table: Scheme - Field: Scheme

dbpDefineRelationship "Inventory" "Widgets" "recID" "Color" "recID" ""
dbpDefineRelationship "Inventory" "Color" "Scheme" "Scheme" "Scheme" ""

And that's going downward through tables, or you could have one Master and multiple details:

dbpDefineRelationship "Inventory" "Widgets" "recID" "Color" "recID" ""
dbpDefineRelationship "Inventory" "Widgets" "Name" "Scheme" "recID" ""
dbpDefineRelationship "Inventory" "Widgets" "recID" "Sizes" "recID" ""

Or, you can have more than one relationship to the same master table but different fields:
dbpDefineRelationship "Inventory" "Widgets" "recID" "Color" "recID" ""
dbpDefineRelationship "Inventory" "Widgets" "Name" "Size" "Name" ""

In one case, I have a schedule DB with a schedule table related to a manufacture data table and a pieces table and test data table and a different test data table. They're all related through the recID field and I can easily view the manufacture date, where it was manufactured, what pieces were manufactured, test data of materials used and test data of manufactured pieces. Now if I end a relationship to any of these tables my grid would show all the data in the detail table and not just the record ID number selected in the Master table.

I could at any time end a relationship in a test table, do a query for a particular test result and then redefine the relationship and continue as normal.

Any of these scenarios should work. Hope this helps.

Paul,

Thanks so much for your comments.  Didn't know you had answered.

Thanks for your view on this matter.  I feel better knowing this.

The examples will help.  I have set different relationships.  The code I show I felt maybe was not the best idea of creating relationships and ending them.

As you said if I can define them after the tables are open, I shouldn't have to deal with them afterwards.

Thanks again.