Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 48
  1. #31
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Quote Originally Posted by Welshgasman View Post
    If you want to link assetid to the many table, then it would be the pk of the one table?, in this case assetid?
    Thanks. So AssetTBL-The Primary Key Should be AssetID and that will be the One
    SampleTBL will need an AssetID field and that will be the Many, but not the PK?

  2. #32
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,903
    No it will be the FK, that is how they will be linked.
    https://m.youtube.com/results?sp=mAE...ss+one+to+many
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #33
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    How about now?
    Attached Files Attached Files

  4. #34
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,903
    That looks a lot better.

    However I would not leave a PK as ID, especially in more than one table, so perhaps SampleID?
    Same with AssetID in Sample table, perhaps call that AssetIDFK.

    Reason being Access gets confused as it will not know which one you are talking about in which table unless tou qualify the field name with the table name. So I prefer to give them unique names, especially as that is what I did not do when I first started using Access. Also the FK suffix immediately tells you what it is?
    Right now you know that, but 6 months down the line, it will be forgotten.

    Now you would have a mainform for your Asset table and a subform for the Sample table, linked by AssetID.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #35
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Change the name of the PK on the Assettbl?

  6. #36
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,903
    Quote Originally Posted by OlBill View Post
    Change the name of the PK on the Assettbl?
    No leave that alone, change the name of assetid in the sample table to assetidfk.
    Use case, but I am typing on a tablet, so just using lowercase.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #37
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Quote Originally Posted by Welshgasman View Post
    No leave that alone, change the name of assetid in the sample table to assetidfk.
    Use case, but I am typing on a tablet, so just using lowercase.
    On SampleTBL - Does AssetIDFK become the primary key for that table?

  8. #38
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,903
    No.
    It has FK in it for a reason. To indicate it is a Foreign Key?
    PK for Sample table would likely be SampleID ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #39
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Quote Originally Posted by Welshgasman View Post
    No.
    It has FK in it for a reason. To indicate it is a Foreign Key?
    PK for Sample table would likely be SampleID ?
    Ok, AssetTBL - AssetID is now PK
    On SampleTBL - PK is ID (autonumber), FK is AssetIDFK. I have a LeadSampleID and an AsbestosSample ID in my SampleTBL. The two ID numbers are different. Lead will begin with PB and Asbestos ASB. And they can both apply to the AssetID separately.

    In other words, I may have one AsstID with 10 LeadSampleIDs and 5 AsbestosSampleIDs, all different on different dates with different results. The only thing they have in common is the AssetID. I need to tie everything back to the AssetID.

  10. #40
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,903
    Personally I would not have any more than one field with a name of ID. Preferably none. SampleID indicates where it is from and what it is. All my PKs are Autonumber and end with ID, so I know they are what they are.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #41
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    That's what they're called, I didn't name them.

  12. #42
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,903
    Quote Originally Posted by OlBill View Post
    That's what they're called, I didn't name them.
    When you create a table ACcess names the autonumber ID. It is up to you to change it to something meaningful.
    If you just have one table, no big deal. When you have several all with ID in them, then access can get confused and more work for you.

    Same with subforms. Access defauts the subform control name to the same as the subform. I prefer to rename the subfomr control so that I know which item I am referring to.

    You will likely develop your own way, but you can learn by my mistakes, as I started off with ID in all of my tables for my first DB. Quickly learnt not to do that again.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  13. #43
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    I started all over. I have attached my current table relationships. My Lead one is picking up the AssetIDFK to match the AssetIDPK fine. My Asbestos and Asbestos Visual are not, as can be seen in the snips. I have all the relationships set the same as the lead one.
    One-to-Many. Enforce Referential Integrity check. Cascade Update Related Fields Check. Cascade Delete Related Records not check. Join Type-Only include rows where the joined fields from both tables are equal.

    I'm so close! Somebody please!

    Click image for larger version. 

Name:	20220916 Relationships.PNG 
Views:	19 
Size:	30.4 KB 
ID:	48730Click image for larger version. 

Name:	20220916 Lead.PNG 
Views:	18 
Size:	5.1 KB 
ID:	48731Click image for larger version. 

Name:	20220916 Asbestos.PNG 
Views:	18 
Size:	4.2 KB 
ID:	48732

  14. #44
    OlBill is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    May 2021
    Posts
    52
    Good Lord that's big.

  15. #45
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,903
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Page 3 of 4 FirstFirst 1234 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 34
    Last Post: 07-04-2021, 04:55 AM
  2. Replies: 2
    Last Post: 03-13-2018, 12:32 PM
  3. Replies: 9
    Last Post: 07-19-2017, 11:01 AM
  4. Replies: 6
    Last Post: 10-16-2014, 12:55 PM
  5. Linking 2 Tables or Queries
    By vdanelia in forum Database Design
    Replies: 4
    Last Post: 03-01-2011, 03:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums