473,396 Members | 1,766 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,396 software developers and data experts.

Need a function to select a file, before importing from Excel

547 512MB
Currently i use the TransferSpreadsheet acImport method, to import an Excel file called "Athletedata.xls", into a table called "Cyclist".
I would now like to select the file from any directory, instead of having to import it from a specific directory only.
I use this code currently to import the Athletedata.xls file. Please assist

Expand|Select|Wrap|Line Numbers
  1.  DoCmd.SetWarnings False
  2.     DoCmd.TransferSpreadsheet acImport, 10, "Cyclist", "c:\RTBU\AthleteData.xls", True, ""
  3.  
Sep 6 '11 #1

✓ answered by NeoPa

You don't actually use the result returned (strPath) in your TransferSpreadsheet line (#10).

It should look more like :
Expand|Select|Wrap|Line Numbers
  1.     Dim strPath As String
  2.  
  3.     With Me
  4.         strPath = Left(.lblFile.Caption, InStrRev(.lblFile.Caption, "\"))
  5.         strPath = FSBrowse(strStart:=strPath, _
  6.                            lngType:=msoFileDialogFilePicker, _
  7.                            strPattern:="MS Excel,*.xls")
  8.         If strPath > "" Then
  9.             .lblFile.Caption = strPath
  10.             Call DoCmd.SetWarnings(False)
  11.             Call DoCmd.TransferSpreadsheet(acImport, _
  12.                                            acSpreadsheetTypeExcel11, _
  13.                                            "Cyclist", _
  14.                                            strPath, _
  15.                                            True)
  16.             Call DoCmd.SetWarnings(True)
  17.         End If
  18.     End With

6 2006
NeoPa
32,556 Expert Mod 16PB
See Select a File or Folder using the FileDialog Object. If you need more help after that then let us know.
Sep 6 '11 #2
neelsfer
547 512MB
When i use your code and module, it opens up at i can select the Excel file using this code, but i do not get it to import data. Where do i go wrong?
Expand|Select|Wrap|Line Numbers
  1.   Dim strPath As String
  2.  
  3.     With Me
  4.         strPath = Left(.lblFile.Caption, InStrRev(.lblFile.Caption, "\"))
  5.         strPath = FSBrowse(strStart:=strPath, _
  6.                            lngType:=msoFileDialogFilePicker, _
  7.                            strPattern:="MS Excel,*.xls")
  8.         If strPath > "" Then .lblFile.Caption = strPath
  9.          DoCmd.SetWarnings False
  10.      DoCmd.TransferSpreadsheet acImport, 10, "Cyclist", "", True, ""
  11.  
  12.     End With
Sep 8 '11 #3
NeoPa
32,556 Expert Mod 16PB
You don't actually use the result returned (strPath) in your TransferSpreadsheet line (#10).

It should look more like :
Expand|Select|Wrap|Line Numbers
  1.     Dim strPath As String
  2.  
  3.     With Me
  4.         strPath = Left(.lblFile.Caption, InStrRev(.lblFile.Caption, "\"))
  5.         strPath = FSBrowse(strStart:=strPath, _
  6.                            lngType:=msoFileDialogFilePicker, _
  7.                            strPattern:="MS Excel,*.xls")
  8.         If strPath > "" Then
  9.             .lblFile.Caption = strPath
  10.             Call DoCmd.SetWarnings(False)
  11.             Call DoCmd.TransferSpreadsheet(acImport, _
  12.                                            acSpreadsheetTypeExcel11, _
  13.                                            "Cyclist", _
  14.                                            strPath, _
  15.                                            True)
  16.             Call DoCmd.SetWarnings(True)
  17.         End If
  18.     End With
Sep 8 '11 #4
neelsfer
547 512MB
Thx Neopa for the trouble. My data would not import until i changed acSpreadsheetTypeExcel11, to acSpreadsheetTypeExcel9. It is Now working fine
Sep 9 '11 #5
neelsfer
547 512MB
Neopa. I decided to create a standard template in Excel with fixed titles. It works great except for one problem - It creates lots of empty rows. I sorted that with a delete query to get rids of blanks, when viewing the data. Duplicates entries are not an issue because one of my fields prevent duplicates, and the "setwarnings" function keeps the system quiet.
Thx again for the excellent service !!
Sep 9 '11 #6
NeoPa
32,556 Expert Mod 16PB
NeelsFer:
My data would not import until i changed acSpreadsheetTypeExcel11, to acSpreadsheetTypeExcel9.
My bad Neels. That was a guess as I'm working on 2003 myself and only have up to acSpreadsheetTypeExcel9.

As for your Excel template, try opening it, selecting all rows from where the worksheet should end (I'm guessing row #2) to the bottom and deleting them (Using right-click / Delete rather than the Del key - which simply clears their contents). Once this has been saved it should work better as a template for you.
Sep 9 '11 #7

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

Similar topics

4
by: Little PussyCat | last post by:
Hello, I nee to write something that will transfer excel data into an SQL Server table. I have for another database application I wrote have it importing Excel spreadsheet data using cell by...
2
by: zino | last post by:
I have a file that is created in Excel and saved as an htm file. (if I open the file through Excel it open as Excel file, if I click on the file name it open in internet explorer). I need to...
1
by: mail2atulmehta | last post by:
Hi, I do not know if this is right place for this, but i need some help. I have a text file, whose values are seprated by a delimiter. I want to open this file in excel, ( not import it) . I have...
2
by: WODJ | last post by:
Folks, I hope someone out there can please help me, not much hair left with this one. I'm importing excel data into a SQL server database using an Oledb connection in C#. The problemm is that...
3
by: Vardhini Gold | last post by:
Hi, I am Vardhini. The project that I am working for is a web based application. I use ASP.2.0/ VB.NET (Visual studio 2005). Kindly help me in importing excel contents to SQL Database using...
1
by: John Overton | last post by:
I have a new requirement to Import and Export Excel tables into and out of Access 2003. The Excel tables are located on a remote server but I know the path to the Excel Files. Can you please help...
1
by: christiekp | last post by:
I am able to import a file from excel to access manually, using the top row as my headings, successfully. however, when using the TransferSpreadsheet command in a macro, importing, excel 5-7, has...
2
by: jld730 | last post by:
Greetings! I am still new to Python, sorry! I have been searching through many posts on this subject and have attempted to TRY, but I feel really lost. So, any detailed guidance would be oh-so...
15
by: pakerly | last post by:
How would i do this, convert a test file to excel? Lets say my text file has fields like this: NUMBER NAME ADDRESS PHONE 11002 Test1 ...
0
by: chethan g | last post by:
Hi, I need to select the whole Excel sheet in Range object and then need to apply "alignment" and "autofit column width". As I have many merged cells, when I attempt to autofit the column width I...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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
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...

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.