473,320 Members | 2,193 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,320 software developers and data experts.

how to export excel data to access table

I am trying to figure out a way to export any new data entered into an Excel 2003 spreadsheet into an Access 2003 database from the Excel application. I've seen lots of code originating in the Access application, but I want to avoid having to go into Access to do it. The users will be entering data into Excel daily, but no one will be in Access daily- and the info needs to be up to date because it is a source for another application(an Infopath 2003 form)which will also be used daily.

Only the newly entered data would need to be copied, and the primary key would not be in the Excel sheet.

I'm a newbie to VBA,

my code which dont work.....

Expand|Select|Wrap|Line Numbers
  1. Sub DAOFromExcelToAccess()
  2.     ' exports data from the active worksheet to a table in an Access database
  3.     ' this procedure must be edited before use
  4.     Dim db As DAO.Database, rs As DAO.Recordset, r As Long
  5.     Dim rs2 As DAO.Recordset, lngPK As Long
  6.     ' open the database
  7.     Set db = OpenDatabase("C:\FolderName\DataBaseName.mdb")
  8.     ' open first recordset
  9.     Set rs = db.OpenRecordset("TableName", dbOpenTable)
  10.     ' open second recordset
  11.     Set rs2 = db.OpenRecordset("OtherTableName", dbOpenTable)
  12.     ' get all records in a table
  13.     r = 3 ' the start row in the worksheet
  14.     Do While Len(Range("A" & r).Formula) > 0
  15.     ' repeat until first empty cell in column A
  16.         With rs
  17.             .AddNew ' create a new record
  18.             ' add values to each field in the record
  19.             .Fields("FieldName1") = Range("A" & r).Value
  20.             .Fields("FieldName2") = Range("B" & r).Value
  21.             .Fields("FieldNameN") = Range("C" & r).Value
  22.             ' add more fields if necessary...
  23.             ' get the primary key
  24.             lngPK = .Fields("AutoNumField")
  25.             .Update ' stores the new record
  26.         End With
  27.         With rs2
  28.             ' do something with the other recordset here
  29.             ' you can use lngPK
  30.         End With
  31.         r = r + 1 ' next row
  32.     Loop
  33.     rs2.Close
  34.     Set rs2 = Nothing
  35.     rs.Close
  36.     Set rs = Nothing
  37.     db.Close
  38.     Set db = Nothing
  39. End Sub
  40.  
  41.  
Dec 21 '12 #1
2 3426
NeoPa
32,556 Expert Mod 16PB
Prasad Joshi:
my code which dont work.....
To save my simply deleting the question, which seems a shame as you've not done such a bad job, can you explain what your code is trying to do, what is not working, and in which way it is not working. That means any error messages you see and which line of code it crashes on if it crashes, or what makes you believe it isn't working if it doesn't crash.

It's obviously difficult for us to answer a question if you don't include any real information in it.
Dec 21 '12 #2
zmbd
5,501 Expert Mod 4TB
Respectfully, may I inquire as to why the data isn't simply being entered into access directly? A lot of the time, there appears to be no really good reason.

This seems to be such a common occurance. In fact, in my lab, we started out with Lotus123 then moved to Excel because we designed the benchsheets in the spreadsheet program; thus, it was an easy way to store the data electronically. We had a steep learning curve moving to a database solution because, "We've always done it this way..."
I've hundreds, maybe thousands of individual workbooks and worksheets - some based on daily (as in new file each day) or monthly (new file each month) data groupings.
The legacy datamanagement is a total nightmare! I finally did a perminate archive (as in no recovery) of the almost 20 year old lotus files as we nolonger have a way to access that data.
Dec 24 '12 #3

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

Similar topics

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....
3
by: Santa-D | last post by:
I've got an excel sheet that I need to import into a table, however, I want the function to automatically manipulate the data prior to it being imported. For example, i have a field called and...
5
by: daicakien | last post by:
hi everybody, im developing access db. my user want to export some column of the table( in access) to Excel( he may choose from list box of form). do you have any idea about it? thanks
1
by: rajangjr | last post by:
hi every one.... can anyone tell me the java code for converting excel data in to the database
1
by: dbalan | last post by:
I have excel file where the data is in horizontal manner. I have an output in access table, in vertical manner. I have a snap shot of data which I would like to attach which better describes my...
1
by: panku007 | last post by:
hi All, I wanted to export excel data into ms word document through java coding.So please send me reply,according to my question. thanks
1
by: san1014 | last post by:
Hi How to import and export excel data into oracle database using java. Thank you
7
by: beulajo | last post by:
Hai. I have student marks in excel sheet. I need to export this data in to msaccess. I have no problem in exporting the data. My excel sheet is in this format I have 40 students. Each student had...
12
by: anand padia | last post by:
I have a master access table where we store all the employee information. I have various application developed in excel which imports and uses information in master. Now I want to develop a excel...
3
by: prashantdixit | last post by:
Hi, I am trying to export excel data to text file in a particular format. The Format for each ROW of Excel is like IMAN_ROOT/bin/import_file -f=<Column A> -type=<Column B> -d=<Column C>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.