Only IDs visible in Excel Import from Access

Closed
PNyiam Posts 21 Registration date Tuesday July 17, 2018 Status Member Last seen September 5, 2018 - Aug 29, 2018 at 10:34 AM
 Blocked Profile - Sep 7, 2018 at 08:14 PM
Hello,

I have set up a VBA import to Excel from Access (using code I found during a number of searches online: (https://www.mrexcel.com/board/threads/exporting-data-from-access-2007-to-excel-2007-using-vba.587416/ to allow some data analysis.

The VBA works well with a couple small but important exceptions...The table I am importing to excel draws data from two other tables (Facilities and Machines). When the data comes across to excel it only displays the relevant IDs in the in the table rather than the fields that are shown in the table on access. Is there something I can do so that it displays the data as it appears in access? I have placed a copy of the code below for reference:



Thanks

Related:

2 responses

Blocked Profile
Aug 29, 2018 at 04:41 PM
OK, lets say that your tables are structured as so:

tblMachine

ID--------MachineName-------------Location
100-----"Drill Press"-------1
110-----"Lubricator"-------2

tblBuilding
ID---------BuildingName
1----------"Main Building"
2----------"Production1"


And you want to place the following data into a table called tblMaintenance:
ID----------EQ----------------Location
10000---Drill Press-----Main Building

Then you need to create a JOIN in your query, when you pull the data. SO you will JOIN table based on ID's

Joins work as such:
(INNER) JOIN: Returns records that have matching values in both tables.
LEFT (OUTER) JOIN: Return all records from the left table, and the matched records from the right table.
RIGHT (OUTER) JOIN: Return all records from the right table, and the matched records from the left table.

So, in this case, your SQL statement would be:
SELECT tblMachine.MachineName, tblBuilding.BuildingName
FROM tblBuilding
INNER JOIN tblMachine ON tblBuilding.[ID] = tblMachine.[Location]
WHERE (((tblBuilding.BuildingName)="Main Building"));


The above sql will produce:
MachineName BuildingName
Drill Press Main Building


I have also set the RELATIONSHIP of Building to Machine in Relationships. See image:

0
PNyiam Posts 21 Registration date Tuesday July 17, 2018 Status Member Last seen September 5, 2018
Aug 30, 2018 at 07:11 AM
Thanks, I have assigned all of the relationships and can get a query that shows the Facility names using:

SELECT PlannedMaintenance.Facility, FacilitiesList.Facilities
FROM FacilitiesList
INNER JOIN PlannedMaintenance ON FacilitiesList.[ID] = PlannedMaintenance.[Facility]

How do I go about building this into either a query that will join the facilities and assets with the whole of the PlannedMaintenance table, or add this to the VBA code above that imports the access data into excel? Just now I seem to have a number of bit of the puzzle, but don't know how to join them together.

Thanks.
0
Blocked Profile
Aug 30, 2018 at 05:32 PM
If you want to nail those ID's together, use relationships. Or, just build the JOIN into a query. ACCESS doesn't use views, or you could build a VIEW with the join, and query the view, but this isn't a valid solution on Access. YOur query BUILDs that relationship.
0
PNyiam Posts 21 Registration date Tuesday July 17, 2018 Status Member Last seen September 5, 2018
Aug 31, 2018 at 06:19 AM
Ok, so managed to make a little progress, but still not able to achieve the desired result...I have tried to put as much info on the problem as possible to help. This is pretty much the last hurdle to overcome before the database is ready for trial use, so hopefully we can crack this.

I have gone through the relationships and as far as I can tell these have been secured as much as possible.



I managed to get most of the information to show by running the SQL below to form a query, however as you can see from fields 2 and 3 it just dropped the info into the table, where all I really want is for column 4 to show the current info but associated with the correct information.

SELECT *
FROM FacilitiesList
INNER JOIN PlannedMaintenance ON FacilitiesList.[ID] = PlannedMaintenance.[Facility];



This is some of the excel output from my test data, columns D, E and G are showing the IDs rather than the wanted field data but I don't know how to form the SQL JOIN query so that it will provide all of the JOINS.



So basically I need an SQL Statement that will populate a query with all of the PlannedMaintenance table but overwrite (or JOIN etc); PlannedMaintenance.[Facility] with FacilitiesList.[Facilities], PlannedMaintenance.[Machines] with AssetList.[Combined Description] and PlannedMaintenance.[Frequency] with PeriodType.[PeriodType].

I'm not even sure how clear all of that is, but do you think you could help me with the SQL statement? I have looked through numerous tutorials, forums and pages, but they seem to mostly present two fields from two different tables , rather than presenting one whole table with a value adjusted using a join, so am pretty stuck now. Otherwise maybe I am not using the relationships right so if you know a way to force access to prioritise the linked fields when doing the export to excel that would work as well.

Thanks
0
Blocked Profile
Aug 31, 2018 at 11:16 AM
OK< what do you need selected, on what tables?
Then, how do you wish tables to be linked?
0
PNyiam Posts 21 Registration date Tuesday July 17, 2018 Status Member Last seen September 5, 2018
Sep 2, 2018 at 12:35 PM
I need all of the fields from the green and white xls table from the previous post, which is made up as follows:

[ID] - from PlannedMaintenance(Table)

[Date Recorded] - from PlannedMaintenance(Table)

[Recorded By] - from PlannedMaintenance(Table)

[Facility] - derived from FacilitiesList(Table).[Facilities](Field) (The name shows on PlannedMaintenance(Table) but only the relevant ID number shows on excel import, as per the xls table image in previous post)

[Machine] - derived from AssetList(Table).[Combined Description](Field) (The name shows on PlannedMaintenance(Table) but only the relevant ID number (unique key) shows on excel import, as per the xls table image in previous post)

[Frequency] from PlannedMaintenance(Table)

[Period] - derived from PeriodType(Table).[PeriodType](Field) (The Unique ID Key shows on PlannedMaintenance(Table) but would like the period type displayed

[Description] from PlannedMaintenance(Table)

[Completion Date] from PlannedMaintenance(Table)

[Date Worked] from PlannedMaintenance(Table)

[# Employees Worked] from PlannedMaintenance(Table)

[Completed By] from PlannedMaintenance(Table)

Hope that is what you were looking for.

Thanks.
0
Blocked Profile
Sep 7, 2018 at 08:14 PM
Ok, so because I have been spending time trying to find storage for a new HCC with 400TB storage, I have been slow. But, its Friday, and its fun time, so I thought I would crack this open.

There are flaws in the table design.
Here is how far I got:

SELECT PlannedMaintenance.ID as [ID],
Date Recorded.planeedMaintenance as [Date Recorded],
PlannedMaintenance.Recorded By as [Recorded By],
FacilitiesList.Facilities as [Facility],


Let us start with "Two word Data Elements". That is not desirable. You need to NOT/STOP use(ing) TWO word ELEMENTS. Use ThisMethod or This_Method. You can even use tblDateRecorded.

Then, you wish to have a machine from assetlist, but there is no other "combined description" listed to key against.


Here is an example of how to link JOIN the tables:


SELECT tblMachine.MachineName, tblBuilding.BuildingName
FROM tblBuilding
INNER JOIN tblMachine
ON tblBuilding.[ID] = tblMachine.[Location]
WHERE (((tblBuilding.BuildingName)="Main Building"));


Below are the tables:




And here is the product.....


This Product finds all machines in the "Main Building".

Does that help out? I understand there is no real answer here, but I hope you see how to scale your project the right way. What's next?

0