Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    annonymous is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2022
    Posts
    9

    Linked Tables Merge

    Hi,

    I use these forums a lot for advice, and help, so thanks to the community for helping simpleton, like myself

    I don't code using freehand, i just use the guided approach.

    My issue is, I now want to merge two linked sheets, into one, and using those results create a query. So i want all of the data displayed, from both sheets, so every unique FLOW ID.

    As you can see from the screenshot i don't really have that option. Is it not possible to merge using linked sheets?

    I've attached a screenshot.
    Attached Thumbnails Attached Thumbnails acess.jpg  

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    Not sure why you would have 2 tables with the same fields. Perhaps you could append the data from one to the other.

    Alternatively you could use a UNION query to join the data from the two tables. Unfortunately, you would need to write the SQL statement for the query. See: https://www.w3schools.com/sql/sql_union.asp

    Post back if you need further help
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  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,535
    Your UNION query would be something like:

    SELECT [Flow ID], [Vessel],[Vessel IMO], [Load Country], [Load Port] FROM [Flows]
    UNION
    SELECT [Flow ID], [Vessel],[Vessel IMO], [Load Country], [Load Port] FROM [Flows 2];

    I can't see the names of the other fields. BTW It would be better NOT to have spaces in the names of any Objects e.g. "LoadPort" rather than "Load Port" and "Flow2" rather than "Flow 2"
    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
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,910
    I cannot see the purpose?, as the ID fields are linked, so surely duplicate information?
    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
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,651
    So i want all of the data displayed, from both sheets, so every unique FLOW ID.
    Maybe a more detailed description of the 2 excel sheets would help.
    What's the same and what's different between the 2 data sources?
    Are these matching data sets and you want to merge missing data from flow2 into flow, or vice versa?
    Are the FlowID's the same in both files?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    annonymous is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2022
    Posts
    9
    Quote Originally Posted by Welshgasman View Post
    I cannot see the purpose?, as the ID fields are linked, so surely duplicate information?
    Sorry, its time series data, Historical part is in one sheet, the current part is in the other

  7. #7
    annonymous is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2022
    Posts
    9
    Quote Originally Posted by Bob Fitz View Post
    Not sure why you would have 2 tables with the same fields. Perhaps you could append the data from one to the other.

    Alternatively you could use a UNION query to join the data from the two tables. Unfortunately, you would need to write the SQL statement for the query. See: https://www.w3schools.com/sql/sql_union.asp

    Post back if you need further help
    Hi Thanks for this. Really kicked me in the right direction. Im now at this point, trying to do an inner left join to bring the route taken based on each of the ID's. I've lifted the script from one of the other queries i ran, using the guided system. Am I missing somethingClick image for larger version. 

Name:	access 2.PNG 
Views:	9 
Size:	40.0 KB 
ID:	49239?

    SELECT [FlowID], [Vessel],[VesselIMO], [LoadCountry], [LoadPort] FROM [FlowsCurrent] LEFT JOIN [Traced_Cargoes] .[Flow ID] = [Traced_Cargoes].[ROUTE])
    UNION SELECT [FlowID], [Vessel],[VesselIMO], [LoadCountry], [LoadPort] FROM [FlowsHistory] LEFT JOIN [Traced_Cargoes] .[Flow ID] = [Traced_Cargoes].[ROUTE]);

  8. #8
    annonymous is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2022
    Posts
    9
    Quote Originally Posted by moke123 View Post
    Maybe a more detailed description of the 2 excel sheets would help.
    What's the same and what's different between the 2 data sources?
    Are these matching data sets and you want to merge missing data from flow2 into flow, or vice versa?
    Are the FlowID's the same in both files?
    Hi, thanks for responding. each flow ID is unique, its data spanning many years, and each flow id represents a new entry, I am combining the data into one query.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,910
    So what is the reason for the link? if they can never be the same?

    Just append all into Flow3.
    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

  10. #10
    annonymous is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2022
    Posts
    9
    Quote Originally Posted by Welshgasman View Post
    So what is the reason for the link? if they can never be the same?

    Just append all into Flow3.
    Because they are linked sheets i dont think you can

  11. #11
    annonymous is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2022
    Posts
    9
    Quote Originally Posted by Bob Fitz View Post
    Your UNION query would be something like:

    SELECT [Flow ID], [Vessel],[Vessel IMO], [Load Country], [Load Port] FROM [Flows]
    UNION
    SELECT [Flow ID], [Vessel],[Vessel IMO], [Load Country], [Load Port] FROM [Flows 2];

    I can't see the names of the other fields. BTW It would be better NOT to have spaces in the names of any Objects e.g. "LoadPort" rather than "Load Port" and "Flow2" rather than "Flow 2"
    Hi Bob, Thanks a ton for your help. IVe responded to this, its really helpful, im just waiting for the moderator to approve

  12. #12
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    Quote Originally Posted by annonymous View Post
    Hi Bob, Thanks a ton for your help. IVe responded to this, its really helpful, im just waiting for the moderator to approve
    You're welcome. Always glad to help when I can.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  13. #13
    annonymous is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2022
    Posts
    9
    Quote Originally Posted by Bob Fitz View Post
    You're welcome. Always glad to help when I can.
    Ill re-post, see if it works. The current query looks like this


    SELECT [FlowID], [Vessel],[VesselIMO], [LoadCountry], [LoadPort] FROM [FlowsCurrent]
    UNION SELECT [FlowID], [Vessel],[VesselIMO], [LoadCountry], [LoadPort] FROM [FlowsHistory];

    I want to add to it, so it brings in the route taken. Please see the attached.

    SELECT [FlowID], [Vessel],[VesselIMO], [LoadCountry], [LoadPort] FROM [FlowsCurrent] LEFT JOIN [Traced_Cargoes] ON [Tradeflows].[FlowID] = [Traced_Cargoes].[ROUTE])
    UNION SELECT [FlowID], [Vessel],[VesselIMO], [LoadCountry], [LoadPort] FROM [FlowsHistory] LEFT JOIN [Traced_Cargoes] ON [Tradeflows].[FlowID] = [Traced_Cargoes].[ROUTE]);

    Click image for larger version. 

Name:	access 2.PNG 
Views:	9 
Size:	40.0 KB 
ID:	49240

  14. #14
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    I think you need to save the following query which I think you've called TestQuery:
    SELECT [FlowID], [Vessel],[VesselIMO], [LoadCountry], [LoadPort] FROM [FlowsCurrent]
    UNION SELECT [FlowID], [Vessel],[VesselIMO], [LoadCountry], [LoadPort] FROM [FlowsHistory];

    Then create a new query. Add "TestQuery" and "Traced_Cargoes" to the new query and join on the appropriate fields.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  15. #15
    annonymous is offline Novice
    Windows 11 Office 365
    Join Date
    Dec 2022
    Posts
    9
    Quote Originally Posted by Bob Fitz View Post
    I think you need to save the following query which I think you've called TestQuery:
    SELECT [FlowID], [Vessel],[VesselIMO], [LoadCountry], [LoadPort] FROM [FlowsCurrent]
    UNION SELECT [FlowID], [Vessel],[VesselIMO], [LoadCountry], [LoadPort] FROM [FlowsHistory];

    Then create a new query. Add "TestQuery" and "Traced_Cargoes" to the new query and join on the appropriate fields.
    Ah thanks. Might sound stupid, but in VBA, and native excel, or a result to be held in memory, you need to use an array. If one query creates the table, and you start another query, wouldnt the results be just replaced with the new?

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

Similar Threads

  1. Merge two tables
    By joethall in forum Access
    Replies: 8
    Last Post: 02-06-2019, 03:59 PM
  2. Merge Tables
    By cfobare79 in forum Access
    Replies: 21
    Last Post: 05-02-2015, 03:53 PM
  3. Replies: 5
    Last Post: 02-02-2012, 06:42 PM
  4. Merge linked tables!
    By thaonguyen1013 in forum Access
    Replies: 14
    Last Post: 02-01-2012, 04:03 PM
  5. How do I Merge Four Tables Together
    By SteveI in forum Queries
    Replies: 1
    Last Post: 03-04-2010, 10:53 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