473,503 Members | 13,381 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 1213
jforbes
1,107 Recognized Expert Top Contributor
FileDialog.InitialFileName 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.FileDialog
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 TransferSpreadsheet 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 TransferSpreadsheet 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,557 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
2673
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
7690
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
8695
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...
2
1906
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...
6
1632
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...
3
5533
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...
2
4677
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
7818
by: shilpag | last post by:
How to export data to multiple excel worksheets using php can anyone help on this please
3
1517
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...
0
2791
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...
0
7098
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...
0
7296
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
7470
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
5604
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,...
1
5026
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...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
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...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
405
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...

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.