Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 12th, 2008, 03:55 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Ottawa, , Canada.
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default import data from excel

Hi,

Is there a way to build a form in Access so that I can just point to an excel file and have it do its 'magic' in the background to import it without going through all the steps of the import wizard...

In essence what I want is a form to pop up, browse to said excel file and it will do it... all in one shot... non of the excess import wizard steps.

Reply With Quote
  #2 (permalink)  
Old February 12th, 2008, 05:05 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Are you wanting to import the data to a new table each time or completely refresh a table with all new data or append records to the table?


dartcoach
Reply With Quote
  #3 (permalink)  
Old February 13th, 2008, 03:28 PM
Friend of Wrox
 
Join Date: Mar 2004
Location: Ottawa, , Canada.
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would want to append the data to a new table each time...

Reply With Quote
  #4 (permalink)  
Old February 14th, 2008, 09:52 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ok, is the excel file always the same format?

dartcoach
Reply With Quote
  #5 (permalink)  
Old February 14th, 2008, 11:40 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Ottawa, , Canada.
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes the layout will always be the exact same thing...

Reply With Quote
  #6 (permalink)  
Old February 14th, 2008, 11:48 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Kansas City, Missouri, USA.
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ok. Do the import once, manually to create the table. Make sure you edit the column names on the new table to be something meaningfull.

Put a button on a form and put this code behind hit:

   'Requires reference to Microsoft Office 12.0 Object Library.

   Dim fDialog As Office.FileDialog
   Dim varFile As Variant
   'Set up the File Dialog.
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
   With fDialog
      'False, the user clicked Cancel.
      .Filters.Clear
      .Filters.Add "Excel Spreadsheets", "*.xls"
      If .Show = True Then
         For Each varFile In .SelectedItems
            DoCmd.RunSQL "Delete * from TableName"
            DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel7, "TableName", varFile, False
         Next
      Else
         MsgBox "You clicked Cancel in the file dialog box."
      End If
   End With


Hope this helps.


dartcoach
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to import excel data into sql server khaink ASP.NET 1.0 and 1.1 Basics 1 July 31st, 2007 09:10 PM
How can we import the data from Ms Excel balesh ASP.NET 1.0 and 1.1 Professional 1 June 8th, 2006 02:15 PM
Import Excel data into a workbook Derek_05 Excel VBA 5 May 31st, 2006 02:02 PM
how to import data from excel,csv into sql server therisingsun ASP.NET 1.0 and 1.1 Basics 2 October 1st, 2005 12:17 AM
Excel Data Import bmains ASP.NET 1.x and 2.0 Application Design 4 April 14th, 2004 02:12 PM



All times are GMT -4. The time now is 07:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.