473,657 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing data from multiple Excel Worksheets

15 New Member
I'm given an Excel file, which is an export out of our main student data system. The file has five tabs that I need to pull data from into five temporary Access tables.

Originally I had hard-coded the location and name of the Excel file. However, I cannot guarantee that the users will honour my file location and filename requirement. I found a function that lets them browse to the Excel file in order to import data from a Worksheet.

It all works very well, but since there are multiple Worksheets in the Excel file that need to be imported the current function and code I'm using causes the user to re-browse(?) each time they are ready to import the data from the next Worksheet. I'd rather not force them to go through the unnecessary step of browsing four more times for the same file.

I have a feeling that the answer is somewhere in the code, meaning it does retain the file and name location. I'm just unclear if that's true, and if so, how to use this information.

Here is the function:

Expand|Select|Wrap|Line Numbers
  1. Function selectFile()
  2.     Dim fd As FileDialog
  3.     Set fd = Application.FileDialog(msoFileDialogFilePicker)
  4.      With fd
  5.         If .Show Then
  6.             selectFile = .SelectedItems(1)
  7.         Else
  8.             End
  9.         End If
  10.     End With
  11.      Set fd = Nothing
  12. End Function
  13.  
Here is one of the lines of code I'm using to import data from one of the tabs:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "tblMathTempData", selectFile, True, "Math!"
  2.  
There are four more temp tables and corresponding subject Worksheet tabs that are very much the same as what is shown in one above and the code for those tabs is similar.

Any help would be very much appreciated.
Mar 30 '16 #1
3 1221
jforbes
1,107 Recognized Expert Top Contributor
FileDialog.Init ialFileName can be set to before calling FileDialog.Show to have the Dialog open on a particular FileName Or Directory. Here is a link to the rest of the information Microsoft has on Office.FileDial og
Mar 30 '16 #2
PhilOfWalton
1,430 Recognized Expert Top Contributor
Two alternatives.
I hold all my external file details in a table. Before running your TransferSpreads heet you can do a Dir to check the file exists, if not, load it into the table and use a DLookup to retrieve the table name. That way unless the file moves, you only have to set up the location once.
Method 2. I am assuming you have a form with a Command Button to run the TransferSpreads heet routine. (If you are only ever going to use 1 external file this will work) Define SelectFile in the header of the Module. Change the name of Function SelectFile() to something else say Function SelectExcelFile ()
That way by running that function, SelectFile is loaded and available to all Functions and Subs while the form is open.
So on opening the form, the first thing you do is run the SelectExcelFile () to load a file name into SelectFile.

Phil
Mar 30 '16 #3
NeoPa
32,568 Recognized Expert Moderator MVP
You may find Select a File or Folder using the FileDialog Object helpful.
Mar 31 '16 #4

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

Similar topics

0
2678
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet. mainly i need to export data to multiple worksheets. it is very urgent to us. thanks Regards gaffar.
7
7694
by: Michal Maciejczak | last post by:
Is it possible to import data from excel file into php and than put it in mysql database?
4
8703
by: paul.chae | last post by:
I have a table in Access with about 3000 records. There are ~60 unique values in the ID field for the 3000 records. What I would like to do is automatically generate multiple Excel worksheets within a single workbook with these records. I would end up with around 500 worksheets, 1 for each unique ID value. I was thinking this could be done if I have an exported flag column in the table, and I search for the max (or min) on the ID...
2
1914
by: ScardyBob | last post by:
Hello, I am having trouble importing data from an Excel Worksheet. When I try to import the data, everything works except certain columns that contain dates, where it replaces the date with a null in the access table. To import the data I do the following. 1. Create a table based on the excel spreadsheet setup with the following query sSQL = "INSERT INTO " & TblName & " SELECT * " _
6
1662
by: sachinkale123 | last post by:
I am working on an application Where I want to import data from Excelsheet to Dataset. But While doing that i am facing following problems: 1) When I close excelsheet and try to import data from excel it gives me following error. Code is as follows: public DataTable originalData1(String _filename, String _sheet) { OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ _filename +...
3
5559
habby0123
by: habby0123 | last post by:
I am trying to export data to Excel from a query in Access. There is a unique "Sales Region ID" and various "Territory#'s" for each Region. I would like one excel workbook for each region, and a worksheet for each Territory # assigned to that region. I do something similiar with a report that I programmatically convert to a pdf and it works fine, but I'm having a little trouble with the excel export. Can someone give me some advice? (Below is my...
2
4684
by: muddasirmunir | last post by:
I want to know how can we Import data from Excel into Excel Using vb6. Any help where can i start ?
6
7858
by: shilpag | last post by:
How to export data to multiple excel worksheets using php can anyone help on this please
3
1519
by: Wiredboy | last post by:
Hi to All!! I need to inmport a Data from Excel to Access but the tables in Access are defined with a primary Key that is formated as an auto number (I'm using a template that I found on Internet!!) and it is giving me an error when i try to import it to my database, I can't. Also there are other fields on the table that are formatted to make a link to a list on the lookup properties than when i try to make the process, it deletes all the...
0
2829
by: sravan | last post by:
I am producing 5 different Excel worksheets (.csv file) using Perl. I want to combine all these as one file (Excel workbook) with 5 different worksheets rather then have 5 seperate files. here is the script i'm using now .. #!/usr/bin/perl -w use lib "/csv2xl/lib/site_perl"; use strict;
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7333
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6167
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1957
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1620
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.