Results 1 to 14 of 14
  1. #1
    Giles64 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    21

    Tab Control Subform - Foreign Keys Not recorded in repsective tables

    Hi
    I am an access novice and would appreciate some help please. Bear with me if I have not shown correct protocol and/or terminology.
    I am trying to set up a database where each record in tblSDSRegister can have multiple Risk Assessments conducted throughout the life of the product. The physical Risk Assessment form these tables are based on has lots of controls so I have made 5 tables with a foreign key relating back to tblRiskAssessment.
    I have placed the 5 subforms on a tab control – so these individual pages will form one record once brought back together. The 5 tables are named tblSDSRequest, tblSDSDetails, tblSDSHealthEffect, tblSDSControlMeasures, tblSDSEvaluation
    Each Risk Assessment can only have a maximum of one entry in each of the 5 related tables. I do not seem to be able to get the relationship right. I thought I needed a junction table to synchronise the tabbed subforms but I have confused myself so much I not sure anymore. The foreign keys are not being recorded in the respective tables? Please see attached.
    I have tried using one table and a single form and one table with multiple subforms, each has their own problems unfortunately.
    I have no experience in coding at all, so please be patient and explain how and why, that would be much appreciated.
    I am hoping someone can offer some guidance as to how best to approach this, thanks in advance.
    Attached Thumbnails Attached Thumbnails SDS Relationships.jpg  
    Attached Files Attached Files

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi

    If you add a field named "AssessmentDate" to the table "tblSDSRiskAssessment"

    This field needs to be populated before you can add data to all the tables in the Tab Control.

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Please review this updated file. I have changed the relationships, changed the Details table (removed one of each pair of mutually exclusive fields - left the last one for you - ShedulePoison) and update the subform to use option groups instead of independent check-boxes, etc.
    You will see that I moved the Reviewed By to the Risk Assessment table to give you a field to enter to force the creation of the new PK (the tab is disabled in code until you have a valid SDSRAID_PK). I had to change the combo for the ReviewedBy into a textbox as you haven't included its row source table(s). Note that in that combo you are correctly storing the PersonId but in the bound table you set up the field as text, should be Number (Long).

    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I would suggest you stop and evaluate the table designs. It looks like at least 4 of the tables are converted from or designed like spreadsheets.

    Examples:

    tblSDSControlMeasures (currently 22 fields /should be 4 fields)
    -----------------------
    SDSCMID_PK
    SDSRAID_FK
    ControlMeasureID_FK ..Link to tblControlMeasureTypes (Ventilation, Spillage, Air Monitor, Waste, Enviro, PPE, Transport, ...) <- this is data; not attributes
    Remark (or Comment)


    tblSDSDetails (currently 9 fields / should be 4 fields)
    -------------
    SDSDID_PK
    SDSRAID_FK
    ClassID_FK ................Link to tblClassTypes (Design For Purpose, Classified Hazardous, Classified Dangerous Goods) <- this is data; not attributes
    ScheduleTypeID_FK . ...Link to tblScheduleTypes (Schedule Poison, NonSchedule Poison)


    tblSDSHealthEffects
    -------------------
    SDSHEID_PK
    SDSRAID_FK
    ExposureTypeID_FK ....Link to tblExposureTypes (Skin, Eyes, Inhalation,.....) <- this is data; not attributes
    Remark

    tblSDSEvaluation
    ----------------
    SDSEID_PK
    SDSRAID_FK
    ApprovedByID_FK ......Link to tblApprovers
    AssessorID_FK ..........Link to tblAssessors
    RiskEvaluationID_FK ...Link to tblRiskEvaluationTypes (Significant Remain So, Significant Controlled, Significant Improve Controls)
    RiskComment
    AssessorDate
    ApprovalDate


    (7 new tables - in magenta)


    The redesign of table "tblSDSControlMeasures" (and the other tables) is because if you want to add a new control measure, you would have to change the design of the table, change all of the involved queries, change the design of the forms involved, change the design of reports and any code that uses that table. If the table is designed correctly, all that is involved it adding a new control measure to a table. Done!


    I am not sure about the purpose of table "tblSDSRiskAssessment". I would replace it with table "tblSDSRequest".



    *********************

    Granted, I know nothing of the business you are in, but you should not have tables designed like spreadsheets.....
    These are just my observations....


    Good luck with your project.....

  5. #5
    Giles64 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    21

    Tab Control Subform - Foreign Keys Not Recorded in respective tables

    Thanks for the quick response, I will adjust the independent check boxes.
    FYI – combo box recordsource is below – so it should be alright to reinstate that?
    SELECT [Personnel Record].ID, [Personnel Record].Surname & "," & [Personnel Record].[First Name] AS Expr1, [Personnel Record].[Internal Workforce] FROM [Personnel Record] WHERE ((([Personnel Record].[Internal Workforce])=Yes)) ORDER BY [Personnel Record].Surname & "," & [Personnel Record].[First Name];
    As each record can have multiple risk assessments equally each risk assessment may be reviewed several times, so I have previously pulled current risk assessment details by creating a query which shows the most current “ReviewDate” and “NextReview” then I have created a new query and incorporated other fields from those 5 tables, however that is not working and I’m sure it is due to the change of relationships, would you be able to show me what I have wrong please?
    qrySDSRegisterCurrent should show
    SDSMRID_PK should equal 2 and SDSRAID_PK = 4, but the records show 1 and 3 respectively
    As the setup has changed I must be missing something else?? I have attached sample with queries.

    I also take it that the Risk Assessment table does not require the foreign keys of the 5 tables?

    Your help is much appreciated, thanks for the quick response
    Attached Files Attached Files

  6. #6
    Giles64 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    21
    Hi Vlad thanks for your help however I am having trouble still - I thought I responded to your original post but not sure, can you look at post 5, that is me again.
    Also I am finding an issue when you create a new record in FrmSDSRegister the relationship seems to disappear??

  7. #7
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi Giles

    I have colour coded the links between Pk and FK

    Creating a new record appears to work just fine

  8. #8
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Sorry here with the updated Db
    Attached Files Attached Files

  9. #9
    Giles64 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    21
    Thank you, your are quite right, not sure what I was doing. I have however come across another problem where the qrySDSRegister does not display all records. I'm not sure whether I have missed some "refreshing" as I added a "NextReview"date on tblSDSMonitorReview for record 4, I have tried by adding it through the table and also the form but the record does not come through on the query, help would be much appreciated.

  10. #10
    Giles64 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    21

    Sample database

    Thank you, your are quite right, not sure what I was doing. I have however come across another problem where the qrySDSRegister does not display all records. I'm not sure whether I have missed some "refreshing" as I added a "NextReview"date on tblSDSMonitorReview for record 4, I have tried by adding it through the table and also the form but the record does not come through on the query, help would be much appreciated.
    Attached Files Attached Files

  11. #11
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi Greg

    Look at the revised query in the attached.
    Attached Files Attached Files

  12. #12
    Giles64 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    21
    Hi
    Thanks, but it now shows all records, I was wanting only the most recent record for each SDSNoID_PK which is "currently used", so I would like to see from the query the details of SDSNoID_PK 1 = SDSMRID_PK 2 and SDSRAID_PK 4, SDSNoID_PK 2 = SDSMRID_PK 4 and SDSRAID_PK 6, SDSNoID_PK 3 = SDSMRID_PK 5 and SDSRAID_PK 8. I thought the way to achieve this was to combine the first query qryCurrentReviewDate which gives me those records but i run into trouble when I try and get details from all the other tables - surely it can only be the relationships within the query but I am failing to see it, any help would be appreciated. Thanks again

  13. #13
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    You need to join the query returning the latest review date (max) to the query on both the ID and the date fields. Maybe have a look at the query, I hope that is what you're after.
    As for the combo you can't reinstate it in the sample because you haven't included the actual table (Personnel Record), it should work OK in your actual db.

    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  14. #14
    Giles64 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jul 2015
    Posts
    21
    Excellent! Thank you so much to all of you for your help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form Updating 3 related tables losing Foreign Keys
    By DannyDont in forum Programming
    Replies: 30
    Last Post: 01-29-2021, 03:48 PM
  2. Replies: 6
    Last Post: 09-08-2019, 03:18 PM
  3. Replies: 6
    Last Post: 05-06-2015, 09:01 PM
  4. Replies: 2
    Last Post: 07-15-2014, 10:39 AM
  5. Design dilemma; multiple tables with same foreign keys?
    By squirrly in forum Database Design
    Replies: 9
    Last Post: 08-16-2011, 10:43 AM

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