473,396 Members | 1,998 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.

Please Help with Access and Excel Importing and Code

I am somewhat familar with access, but have no clue to modules and coding. I am trying to develop code or a module that will enable a user to import a specific excel spreadsheet and its' data into a table by pressing a command button. I am able to import excel, however it will not attach to existing spreadsheet. I find myself, having to build an append query for each import which is time consuming and inefficient. I have already checked, my excel columns have the same data. Essentially, I need my command button to browse for the excel file, and import one of the spreadsheets into a specified table. Please help.

Alaurie10@hotmail.com
Sep 24 '07 #1
4 2024
FishVal
2,653 Expert 2GB
Hi, there.
  • I am able to import excel, however it will not attach to existing spreadsheet. I find myself, having to build an append query for each import which is time consuming and inefficient.
    Programmatical iterating through spreadsheet and appending rows to a table will be far more inneficient and time consuming. I suggest you for import purposes to temporarily link Excel ranges and perform append query.
    Something like

    Expand|Select|Wrap|Line Numbers
    1. With DoCmd
    2.     .TransferSpreadsheet  acLink, acSpreadsheetTypeExcel9, _
    3.           "tblTempLink","X:\qqq.xls", , "Sheet2!A:D"
    4.     .RunSQL "INSERT INTO tblImport ( fld1, fld2, fld3, fld3) " & _
    5.         "SELECT tblTempLink.F1, tblTempLink.F2, tblTempLink.F3, tblTempLink.F4 " & _
    6.         "FROM tblTempLink;"
    7.     .DeleteObject acTable,"tblTempLink"
    8. End With
    9.  
  • export is much more simple issue

    Expand|Select|Wrap|Line Numbers
    1. DoCmd.TransferSpreadsheet  acExport, acSpreadsheetTypeExcel9, _
    2.     "tblSomeTable", "X:\qqq1.xls", , "Sheet1!A:D"
    3.  
  • and finally concerning file browsing:
    take a look at this thread file browse button on a form
Sep 24 '07 #2
Thanks FishVal:
I your assistance is greatly appreciated. Please pardon me if I am a little more than naive, but a couple of more questions if I may....

1. Do I paste the code you gave me into the Event Procedure of the command button?

2. I am unfamilar with the color coding, do I change the code written in red with my own?

3. I did perform the browsing code, in a module, and it worked. Do I paste this code before or after the import code that you gave me in the same module?

4. How do I link the code in the module to a macro that will enable me to call the code or link the module directly to the command button?

4. Finally, do I need to create the table that will hold my imported data first, or will access automatically create a temp import table with the code each time? If so, how can I keep the data in another table?
Sep 24 '07 #3
FishVal
2,653 Expert 2GB
Ok. To answer your questions I've written a small example.
DB contains:
Table: tblImport with 4 fields: fld1, fld2, fld3, fld4
Form: contains one button [btnImportXLData]

Here is the code of button [btnImportXLData] Click event handler.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnImportXLData_Click()
  2.  
  3.     Dim dlgPickFiles As Office.FileDialog
  4.     Dim strFileName As String
  5.  
  6.     Set dlgPickFiles = Application.FileDialog(msoFileDialogFilePicker)
  7.  
  8.     With dlgPickFiles
  9.         .AllowMultiSelect = False
  10.         With .Filters
  11.             .Clear
  12.             .Add "Excel files", "*.xls"
  13.         End With
  14.         .Show
  15.         strFileName = .SelectedItems(1)
  16.     End With
  17.  
  18.     Set dlgPickFiles = Nothing
  19.  
  20.     With DoCmd
  21.         .TransferSpreadsheet acLink, acSpreadsheetTypeExcel9, _
  22.               "tblTempLink", strFileName, False, "Sheet2!A:D"
  23.         .RunSQL "INSERT INTO tblImport (fld1, fld2, fld3, fld4) " & _
  24.             "SELECT tblTempLink.F1, tblTempLink.F2, tblTempLink.F3, tblTempLink.F4 " & _
  25.             "FROM tblTempLink;"
  26.         .DeleteObject acTable, "tblTempLink"
  27.     End With
  28.  
  29. End Sub
  30.  
This simple example imports data to table [tblImport] from chosen XL file, Sheet2, Columns A:B. Get this working and will proceed to more friendly interface including selection of sheet to import data from.
Sep 24 '07 #4
Not a problem, give me a couple of days, Have a trainning and unfortunately it is not for programming. Will get this going by Friday.

Thanks
Sep 25 '07 #5

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

Similar topics

2
by: RustyR | last post by:
Hi, I have 5 excel spreadsheets that are exported to me weekly. At first, I could not get them to import. Then I did a File -> Save as and noticed that the Filenames of the spreadsheets...
3
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown....
2
by: T2 | last post by:
I need some code ideas to import Excel into Access using VB. I need to use VB because the Excel column formats are not always consistent. I'm importing a fairly simple spreadsheet. Any...
1
by: winzy | last post by:
I have a table in Access which needs updating from an Excel file. Instead of importing the whole Excel like a new table in Acess, how do I do a partial import/update?? For example, Access table...
3
by: mukeshsrivastav | last post by:
dear sir i want to move form excel to access. i have 5 excel file having same formats and fields.now i want to import all data in one access table. importing one file is easy .but importing and...
28
by: kkadakia | last post by:
I get a daily excel file for a entire month which I want to transfer into Access at the end of the month. So, there are around 20-25 excel files I get by the end of the month, and I would like to...
0
by: upadhyayanuj | last post by:
Hi I have an error while uploading file and then importing it into my sql table The process cannot access the file 'c:\inetpub\wwwroot\FlowLine\Excel File\Fan_Details.xls' because it is being...
15
by: OfficeDummy | last post by:
Hello all! I searched the Internet and this forum for a similar problem, but I found no help... Also, I'm a complete newbie to the fascinating world of programming, VBA and Access, so my question...
3
by: keirnus | last post by:
hello, been searching for a solution on this but all i get are advices for importing data from excel directly to MS Access DB. my case here is different...the sheet in Excel file is not ready...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...

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.