473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Importing Data from One Excel Sheet into Multiple Access Tables Simultaneously

17
Hello all,

I've set up protected Excel sheets that users can paste data into. I then need to be able to pull the data they paste into multiple access tables and then reset the Excel spreadsheet back to the template. For example, the first few columns go to the first table, the next 3 into a second table and so on. Is this possible? I can't think of a way to do it. Thanks in advance for all your help!
Jun 21 '07 #1
5 6387
BradHodge
166 Expert 100+
Here is what I came up with...

1) As could be expected, your field names and data types should be consistent between the Excel Spreadsheet and the Access Tables.
2) You will likely need to have some sort of module to be able to code a pause between trips out to the spreadsheet to get another column. I used this one by Dev Ashish .
3) Here is the code I used...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Import_Click() 
  2. DoCmd.TransferSpreadsheet, acSpreadsheetTypeExcel9, "tblImport1", "C:\Spreadsheet.xls", True, "A:A"
  3. 'Transfers column A from your spreadsheet to the 1st table in your database 
  4. Call sSleep (500)
  5. DoCmd.TransferSpreadsheet, acSpreadsheetTypeExcel9, "tblImport2", "C:\Spreadsheet.xls", True, "B:B"
  6. Transfers column B from your spreadsheet to the 2nd table in your database 
  7. Call sSleep (500)
  8. DoCmd.TransferSpreadsheet, acSpreadsheetTypeExcel9, "tblImport1", "C:\Spreadsheet.xls", True, "C:C"
  9. Transfers column C from your spreadsheet to the 3rd table in your database 
  10. Call sSleep (500)
  11. DoCmd.TransferSpreadsheet, acSpreadsheetTypeExcel9, "tblExcelTemplate", "C:\Spreadsheet.xls", True
  12. Transfers a table in your database with the spreadsheet's column names and no data, back to your spreadsheet. 
  13. End Sub
Hope this helps.

Brad.
Jun 21 '07 #2
rewalk
17
Brad,

Thanks for that bit of code. That definitely helped. However, it led me to another problem. The ID is set by an autonumber in the first table things are copied into. However, this ID needs to be duplicated in all the other tables. The reason for this is because users run reports that pull information together from the various tables in stages, so access needs to know what entries go with what entries in each table. I can't find a way to get access to duplicate the ID from the first table in the other tables. To follow is the specific (simplified) example:

Table 1
ID, Var 1, Var 2
Value:
1, X1, X2
2, Y1, Y2

Table 2
ID, Var 3, Var 4
Value:
1 (assigned from table 1), X3, X4
2 (assigned from table 1), Y3, Y4

Report:
X1, X2, X3, X4
Y1, Y2, Y3, Y4

Thanks again for your help and any ideas on this problem are equally appreciated.
Jun 22 '07 #3
BradHodge
166 Expert 100+
That's a tough one. Since you want all of the tables to share the same ID number, using an AutoNumber on any of them would be illadvised because that number can reset itself, which would cause your data not match up anymore.

I was trying to think of a way to use the date in combo with something else from the record to be the unique ID. So far no luck. I'll keep thinking about, but maybe one of the experts has some thoughts on this one.

Brad.
Jun 22 '07 #4
rewalk
17
Hey Brad,

I just wanted to let you know I ended up figuring it out and wanted to thank you for your help and guidance. The way I did it was using a DoCmd to import the spreadsheet directly to a query which split the information up. Thank you again for all your help.
Jun 25 '07 #5
BradHodge
166 Expert 100+
Glad you found a solution!

Brad.
Jun 25 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
7
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
13
by: Arno R | last post by:
Hi all, I will have to handle a lot of really 'nice' data in a LOT of Excel sheets. It is all about music files (Billboard top 100) I am afraid there really is a sheet for every year ... (Don't...
11
by: Hi5 | last post by:
Hi, I am new to access I usedto work in Oracle and Mysql. I am after a way that enables me to populate a database I designed in access with lots of data which can be sorted in excel sheets, ...
9
by: jillandgordon | last post by:
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I get to the lst step and am told that it was not imported due to an error. ...
3
by: Conrad F | last post by:
Hello All, I know how to import a specific named excel sheet into a datagrid using ADO.NET by setting up a JET connection and then SELECTing data from the sheet. However, for a real world...
2
by: Patrick B. | last post by:
I have an existing excel spreadsheet that my customers MUST continue using. There are 5 different specially formatted cell groups (tables) on one sheet where the use can enter data. The data in...
0
by: DrewYK | last post by:
I have the project that may never end in front of me. I am creating a routine that will take SpreadSheets from Excel and bring them into Access. I am not using any "DoCmd"s because the goal...
4
by: Harshe | last post by:
hello all, I am trying to code, but i am just stuck after importing one sheet. so here is the gist of what i need help with. In a workbook at the start of the year (january) i will have 4...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.