Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2008, 03:55 PM
Friend of Wrox
 
Join Date: Mar 2004
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.

 
Old February 12th, 2008, 05:05 PM
Friend of Wrox
 
Join Date: Jan 2005
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
 
Old February 13th, 2008, 03:28 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old February 14th, 2008, 09:52 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ok, is the excel file always the same format?

dartcoach
 
Old February 14th, 2008, 11:40 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old February 14th, 2008, 11:48 AM
Friend of Wrox
 
Join Date: Jan 2005
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





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





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