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
4 2024
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 -
With DoCmd
-
.TransferSpreadsheet acLink, acSpreadsheetTypeExcel9, _
-
"tblTempLink","X:\qqq.xls", , "Sheet2!A:D"
-
.RunSQL "INSERT INTO tblImport ( fld1, fld2, fld3, fld3) " & _
-
"SELECT tblTempLink.F1, tblTempLink.F2, tblTempLink.F3, tblTempLink.F4 " & _
-
"FROM tblTempLink;"
-
.DeleteObject acTable,"tblTempLink"
-
End With
-
- export is much more simple issue
-
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
-
"tblSomeTable", "X:\qqq1.xls", , "Sheet1!A:D"
-
- and finally concerning file browsing:
take a look at this thread file browse button on a form
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?
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. -
Private Sub btnImportXLData_Click()
-
-
Dim dlgPickFiles As Office.FileDialog
-
Dim strFileName As String
-
-
Set dlgPickFiles = Application.FileDialog(msoFileDialogFilePicker)
-
-
With dlgPickFiles
-
.AllowMultiSelect = False
-
With .Filters
-
.Clear
-
.Add "Excel files", "*.xls"
-
End With
-
.Show
-
strFileName = .SelectedItems(1)
-
End With
-
-
Set dlgPickFiles = Nothing
-
-
With DoCmd
-
.TransferSpreadsheet acLink, acSpreadsheetTypeExcel9, _
-
"tblTempLink", strFileName, False, "Sheet2!A:D"
-
.RunSQL "INSERT INTO tblImport (fld1, fld2, fld3, fld4) " & _
-
"SELECT tblTempLink.F1, tblTempLink.F2, tblTempLink.F3, tblTempLink.F4 " & _
-
"FROM tblTempLink;"
-
.DeleteObject acTable, "tblTempLink"
-
End With
-
-
End Sub
-
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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: 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,...
| |