Hello all, I previously posted under this heading: Importing Data from One Excel Sheet into Multiple Access Tables Simultaneously, but the nature of the problem has changed so I decided to make a new discussion. Thanks to one of the members here I was able to successfully import the data into the tables from the excel spreadsheet and I greatly appreciate his help. However, I've run into a new problem. The first table assigns the unique key to the data, and I can't get this autonumber key to go to the other tables. Here is what I need to happen: Table 1:
Data: 1, X, Y
2, X, Y
3, X, Y Table 2:
Data: 1, A, B
2, A, B Table 3:
Data: 3, C, D
Instead, what is happening is it imports that just the correct data into Table 1, but because of the relationship I have in the second table, with the ID's being linked, it won't import into the second table and instead I get an error message.
I need the tables to be set up this way because on the reporting level I might need to join tables together like this: Report: 1, X, Y, A, B
3, X, Y, C, D
So access needs to be able to see what data matches up with what data in each table.
I've tried to set up code so when it transfers the data from the spreadsheet to the tables it automatically gives the same ID to each one, but I haven't been successful in getting it to work. I also thought of having the data go into a big staging table and then being broken down, but my admins here at work weren't crazy about that idea because they want to keep the database as small as possible.
I'm pretty new to the access scene and could really use some help. Thank you in advance for your time!
2 1626
Here is the code that I've made so far which succesfully imports the files. Special thanks to members ont his network that have helped me fix some quirks in this code in the last discussion I made: -
Private Sub Done_Click()
-
-
Dim File As String
-
Dim LastDataColumn As String, LastDataRow As String
-
Dim LastDataCell As String
-
-
'Set File name
-
File = "C:\Sample Data.xls"
-
-
'Open the file
-
Workbooks.Open Filename:=File
-
-
'Unprotect the file
-
ActiveWorkbook.Unprotect
-
ActiveSheet.Unprotect
-
-
'Obtain the last cell that is used on the sheet
-
LastDataColumn = Chr(Selection.SpecialCells(xlLastCell).Column + 64)
-
LastDataRow = Selection.SpecialCells(xlLastCell).Row
-
LastDataCell = LastDataColumn & LastDataRow
-
-
'Import the data
-
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "ExcelImport", File, True, "A1:M" & LastDataRow
-
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "ExcelImport2", File, True, "N1:" & LastDataCell
-
-
'Clear contents of template
-
Worksheets("Sheet1").range("A2:" & LastDataCell).ClearContents
-
-
'Protect the file
-
ActiveWorkbook.Protect
-
ActiveSheet.Protect
-
-
'Save the file
-
ActiveWorkbook.Save
-
-
'Close the file
-
ActiveWorkbook.Close
-
-
End Sub
-
Instead, what is happening is it imports that just the correct data into Table 1, but because of the relationship I have in the second table, with the ID's being linked, it won't import into the second table and instead I get an error message.
I need the tables to be set up this way because on the reporting level I might need to join tables together like this: Report: 1, X, Y, A, B
3, X, Y, C, D
So access needs to be able to see what data matches up with what data in each table.
As I understand it, you are importing an excel spreadsheet and splitting the rows in the spreadsheet across two access tables and you want to maintain the links across each row.
You are importing A-M into one table, and N into another. Can you change the spreadsheet so that column N becomes column P and then in Column N put in the row numbers, i.e. 1,2,3,to the last row. Then import A-N and N-P into your tables. Column N would become the primary key in each table and you can then link them.
The only other thing I can think of is the temporay table that your admins dont like. If the data was deleted after the import, and the dbs compacted, size would only be an issue during the import.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Eric |
last post by:
Let me start by saying that I'm still very new at PHP/MySql and will
take any advice. :-)
The issues is that every once in a while users get an error when they
use this code. I believe the...
|
by: Sanjay Minni |
last post by:
What is the datatype to be used
for Primary Key columns for most
optimised access given that
- There will be a single column primary key only
- The values will only be integers (but as...
|
by: sfh |
last post by:
Greetings all,
I have a question concerning primary key types.
In the past, I have always created tables with a primary key as an "int" such as:
CREATE TABLE color_id (
color_id int(10)...
|
by: sfh |
last post by:
Greetings all,
(I had posted this in MS SQL on accident, my apologies :( )
I have a question concerning primary key types.
In the past, I have always created tables with a primary key as...
|
by: gilman |
last post by:
Hello there,
we have configured a perfect DB2 HADR pair. After some days, we had
following problem:
After a reboot standby becomes standby, that's ok. Pimary becomes
primary, i tought db2 could...
|
by: sea |
last post by:
Is it a good idea to programatically create a primary key? For example
in a table called names, I have the following fields, (1) firstname
(2)lastname (3) ID
- will it be ok to create a primary...
|
by: misscrf |
last post by:
Ok I have 2 issues.
1) I have a main candidate form with 2 subforms on a tab control:
http://www.geocities.com/misscrf/images/contactcontinouscheckbox.jpg
I have been encouraged to add these...
|
by: Jeff Amiel |
last post by:
7.4.2 running on FreeBSD 5.4.2
I have a table (called "draft" ) that has a bigserial as the primary key.
"check_id bigserial NOT NULL"
I do NOT have an additional index on that column.
I...
|
by: Chirag |
last post by:
I want to create a table with
member id(primary key for Students,faculty and staff )
and now i want to create issues with foreign key as member id
but in references i could not able to pass on...
|
by: sachin |
last post by:
Hi,
I am facing some strange issue in DB2 UDB 9.5.1
I have created a database on DPF implemented environment and I tried
to execute following commands
Db2 create table test ( name char(10)...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |