Results 1 to 6 of 6
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Qry with two fields of same name from different tables?


    Views: 8 Size: 309.3 KB">CompanyTester.zip


    HI all,
    I attached a copy of a db I that I took parts from my main db as so to make smaller...

    db opens to frmCompany, there are two tabs on it with sub forms.
    The issue is that my query that relates to the Locations Tab, (CompanyByLocationQry) ... I need to put CompanyID from tblLocation and not sure how?
    I have CompanyID from tblCompanyByLocation which i need for the qry to work but i also need the CompanyID from the tblLocation so it puts the CompanyID in that
    tbl as well.

    Just not sure how to do it? Suggestions are great...
    Thanks
    Dave

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Hi Dave,

    your design is slightly wrong, you should use the IsPrimary from tblLocations and drop it in tblCompanyByLocation and also drop CompanyID from tblLocations as you already have established the join between the two in tblCompanyByLocation.
    In any case, see if this is what you wanted, just added the field and renamed it then added a new textbox with the same default value as txtCompanyID.

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

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    The issue is that my query that relates to the Locations Tab, (CompanyByLocationQry) ... I need to put CompanyID from tblLocation and not sure how?
    Why?
    I have CompanyID from tblCompanyByLocation which i need for the qry to work but i also need the CompanyID from the tblLocation so it puts the CompanyID in that
    tbl as well.
    Perhaps I'm not understanding all this correctly but I don't understand why you need to change anything.
    What is not working correctly?
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Dave,

    Can you provide a 3-4 line overview description of the business this database is intended to support?
    From my initial view the tables don't really tell a story.
    For example why not have address with the Company?
    If the company has "subsidiaries" in different locations, then perhaps another table(s) may be needed.
    What is the significance of IsPrimary and IsActive? What exactly is IsPrimary (the company, the address...)???
    Why do you need a table of CompanyByLocation? You can get that from a query when needed.
    Last edited by orange; 03-13-2021 at 10:29 AM. Reason: spelling

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi all and thanks for the info...I will try to answer all of you in this reply

    Orange,
    This is a company database to track companies and contacts along with a lot of other info. As stated this is just a snip it of the real db as it is way to big to upload.
    Each company can have multi locations, each location can have multi addresses for that location.
    I dont want the companyID in the tbladdress as i use this for other entities also like people (Not Company Contacts) but personal records which dont have a company,
    The IsPrimary is the lets say "Preferred" Location, address, and so on. It can only be one. The IsActive is if not active, then wont show up after my active (have not set yet in quy's)
    but intend to once completed.
    As far as the question of "Why do you need a table of CompanyByLocation? " my only answer is its the only way i know how to do it.

    Bob,
    The reason for the question is I didnt know the best way to get the CompanyID from tblLocation into the query without changing the name of the other CompanyID from the Junction table.

    And finally Gicu,
    That is pretty much what i was wanting. I will have to play with it. I though i may possible have to change the CompanyID in the Junction Table to CompanyIDfk or somehting and then put a new
    TxtBox on the form and just make its default to match the CompanyIDfk.... I was not aware that you can just change a name in the query field to make that happen like you did it. Nice to know as
    I move thought this. Thank you....

    Again, thank you all for the assistance
    Dave


  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You're very welcome Dave!
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. How many fields should my tables include?
    By kstrecker1701 in forum Database Design
    Replies: 11
    Last Post: 07-25-2018, 05:35 PM
  2. Replies: 1
    Last Post: 04-12-2017, 07:39 AM
  3. How to sum two fields values in different tables.
    By Marcelo Rojas O. in forum Access
    Replies: 1
    Last Post: 03-16-2014, 01:33 AM
  4. tables fields
    By funi.t in forum Database Design
    Replies: 4
    Last Post: 01-13-2012, 01:20 AM
  5. Replies: 1
    Last Post: 06-03-2006, 05:02 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