Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    PMal is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2022
    Posts
    12

    Question Subform Based on Look up


    Hello,

    Hoping this is a simple one, I've tried to search similar post but found nothing....

    I have 2 tables, an equipment list, and an events table. the tables are joined by the serial number entered on the equipment list (the serial number on the events table is a look up based on the equipment table). I've created a form for the equipment list and I want to add a subform that lists all the events for said equipment, so a query based on the serial number but I'm scratching my head. I think my issue is I'm trying to filter a lookup value but I can't seem to find a way around.

    Any help will be greatly received. Hopefully I've explained it well enough but I can provide more information where needed.

    Thanks.

    Last edited by PMal; 07-14-2022 at 02:09 AM. Reason: Added Picture

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    @Pmai
    I do not know what you did to create this thread, but there is no text?
    Clicking on your name gives me this 'Hello, Hoping this is a simple one, I've tried to search similar post but found nothing.... I have 2 tables, an equipment list, and an events...' but if I tried the +more option, I get back to en empty message.

    So please add your question 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

  3. #3
    PMal is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2022
    Posts
    12
    How strange, I tried to add a picture as an edit so something must have gone wrong after this (probably me).

    I have 2 tables, an equipment list and an event list. The tables are joined by the serial number of the equipment. For the Event table, this is a lookup based on the column in the Equipment table. I have created a form for the equipment table and I want to add a subquery report to the bottom of the form to show all the events that are related to that piece of equipment. I'm presuming my issue is because the event side of the query will be based on an ID whilst the Equipment is the Serial Number but I cant seem to find a way to navigate it?

    Hopefully this makes sense.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Sounds like your structure is incorrect?
    I would have
    tblEquipment
    tblEvents
    tblEquipmentEvents

    The latter table is a junction table that links the euipment with any events. I would still use the autonumber ID for both the first two tables. These then get stored in that junction table.

    HTH
    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. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    Your design does not sound right - unless an event can only use one item of equipment.

    Suggest show your table design for each table plus relationships and provide a brief explanation of what an event is

    To add a picture, click on the insert image button - 4th in from the right on the basic menu

    What I would expect to see as an absolute minimum is something like

    tblEquipment
    EquipmentPK
    SerialNum
    EquipmentDesc

    tblEvents
    EventPK
    EventName
    EquipmentFK - links to EquipmentPK
    DateFrom
    DateTo

  6. #6
    PMal is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2022
    Posts
    12
    OK it would appear that my method might be way off, full disclosure, I haven't touched Access in roughly 8 years but after starting a new job, I thought I'd try my hand again, it would seem I'm rusty to say the least.

    The event table is to be used to attached things like maintenance, audits, repairs etc to equipment so I can keep a history of what happens. I've attached the picture of the current set up.

    Click image for larger version. 

Name:	Equipment Table.jpg 
Views:	33 
Size:	158.0 KB 
ID:	48316Click image for larger version. 

Name:	Event Table.jpg 
Views:	34 
Size:	210.2 KB 
ID:	48317Click image for larger version. 

Name:	Relationship.jpg 
Views:	32 
Size:	50.8 KB 
ID:	48318

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Again, I would have thought audit, maintenance etc would be separate tables?

    Also do not use table lookups, do them yourself on the forms.
    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

  8. #8
    PMal is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2022
    Posts
    12
    Quote Originally Posted by Welshgasman View Post
    Again, I would have thought audit, maintenance etc would be separate tables?

    Also do not use table lookups, do them yourself on the forms.
    That seems to have fixed it, taking out the look out from the table. Thank you.

    In regards to the separate table for each event type, it is supposed to just be a snapshot of the history so I don't see a need from my view point, unless there's some reason is Access that I'm not aware of?

    Click image for larger version. 

Name:	Setup.png 
Views:	36 
Size:	25.8 KB 
ID:	48320

  9. #9
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi

    Your Relationships between tblEquipment_Inventory and tblEvents is wrong

    tblEquipment_Inventory currently has a Primary Key of "ID" - this should be "EquipmentInventoryID"

    Then in tblEvents replace "ID" with "EventID"
    Then add a Foreign Key named "EquipmentInventoryID"

    Link the PK from tblEquipmentInventory to the FK in tblEvents
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  10. #10
    PMal is offline Novice
    Windows 11 Office 365
    Join Date
    Jul 2022
    Posts
    12
    Quote Originally Posted by mike60smart View Post
    Hi

    Your Relationships between tblEquipment_Inventory and tblEvents is wrong

    tblEquipment_Inventory currently has a Primary Key of "ID" - this should be "EquipmentInventoryID"

    Then in tblEvents replace "ID" with "EventID"
    Then add a Foreign Key named "EquipmentInventoryID"

    Link the PK from tblEquipmentInventory to the FK in tblEvents

    Hi, I don't think I'm clever enough to do that, my SQL skills are basic to non-existent. With the for sub-query now working as I want it to by joining the serial numbers, will it cause me issues down the line?

  11. #11
    Join Date
    Apr 2017
    Posts
    1,679
    Quote Originally Posted by PMal View Post
    In regards to the separate table for each event type, i...
    Not a separate table for every event type! You need an Events table, where all those event types are defined (EventID, EventName, with values like 1, "Meintenance"; 2, "Audit"; 3, "Repair", etc.), and an ItemEvents table, where is registered, when and for which item an event occurrred, and who did it.

    Edit:
    With such design, as bonus, you get a full history of all events for item. At any time you can see, what and when happened something with this specific item.

    And having all events registered in ItemEvents table, you can clear all event info from Items table - it will be abundant there.

    Another info you have to consider to remove from Items table is location. Have a Locations table where all possible locations for all items are registered, and a ItemLocations table, which will actually be a Item Location Log , where is registered all location changes for every item, along with change date. An advice - add some 'fake' locations, like "Scrapped", "InRepair", "NotInUse", etc. so you can register those movements too!

  12. #12
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi

    You should always link Related Tables using a PK and FK
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    First post was moderated, probably after trying to add picture. I'm not getting notifications of moderated posts, so I just saw this now. Sorry for the delay.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Quote Originally Posted by pbaldy View Post
    First post was moderated, probably after trying to add picture. I'm not getting notifications of moderated posts, so I just saw this now. Sorry for the delay.
    Paul, would you be using a Gmail address on here?
    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

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Quote Originally Posted by Welshgasman View Post
    Paul, would you be using a Gmail address on here?
    Yes, Matrix said that may be the problem, though I recall somebody testing a different provider and it still not working? Not sure, old brain.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-16-2022, 04:08 PM
  2. Cannot add a subform based on a table
    By TenOc in forum Forms
    Replies: 8
    Last Post: 10-22-2021, 11:06 AM
  3. Replies: 6
    Last Post: 07-08-2020, 12:26 PM
  4. Replies: 1
    Last Post: 09-29-2016, 09:32 AM
  5. Replies: 1
    Last Post: 12-15-2012, 12:46 AM

Tags for this Thread

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