473,473 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

compare excel and access table and update changes

7 New Member
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 application that will import all the records from access table or some particular data (defined by field id) in excel spreadsheet. (***successfully acomplished)

User would be able to view the records and make changes to the spreadsheet now when the user closes the file excel will ask if records needs to be updated to the master, if user selects yes I need a VBA code to run through a check which will compare the master with spreadsheet and update the records.

I know I can link the excel spreadsheet and do this easily, however we use this in our office through our network and there are about 50 people who could need to update it at once. Now excel spreadsheet cannot be opened and updated by all at once.

Please let me know if there is a method through which I can use to do this.

Access Master Records have employee info. like EMPID, Name, Manager Name, Date of Joining, Designation, Email.
Jun 28 '10 #1
12 8088
NeoPa
32,556 Recognized Expert Moderator MVP
This sounds like a complicated setup. I would advise against using one such as this as there are so many complications involved, such as which update to keep when there is more than one from the many instances.

That said, the easiest and most reliable would clearly not be a simple Excel process. The Excel part could export a file for the Access part to import. It could even trigger the Access code to start by opening the database. It would be sensible to include the date/time in both the master and the Excel tables so only the latest would be used. Clearly only the updated records should be included in the exports.
Jun 28 '10 #2
anand padia
7 New Member
I was able to achieve little bit...
Expand|Select|Wrap|Line Numbers
  1. Sub UpdateMDB()
  2. Dim cn As Object
  3. Dim rs As Object
  4. strFile = Workbooks(1).FullName
  5. strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
  6.         & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
  7. Set cn = CreateObject("ADODB.Connection")
  8. Set rs = CreateObject("ADODB.Recordset")
  9. cn.Open strCon
  10. strSQL = "SELECT * FROM [Sheet1$] s " _
  11.     & "INNER JOIN [;Database=D:\temp excel\T.mdb;].Table1 t " _
  12.     & "ON s.id=t.id " _
  13.     & "WHERE s.Field1<>t.Field1"
  14. rs.Open strSQL, cn, 1, 3
  15. strSQL = "UPDATE [;Database=D:\temp excel\T.mdb;].Table1 t " _
  16.     & "INNER JOIN [Sheet1$] s " _
  17.     & "ON s.id=t.id " _
  18.     & "SET t.Field1=s.Field1 " _
  19.     & "WHERE s.Field1<>t.Field1 "
  20. cn.Execute strSQL
  21. End Sub
Above code compares the sheet data and writes it however does not update if any new records are updated in excel.

Is there a way to have excel to update any new data found using the same batch technique. Also can I incorporate it in the below mentioned code in any way.
Jun 28 '10 #3
NeoPa
32,556 Recognized Expert Moderator MVP
I would make a few suggestions.
  1. Always declare your procedures as Public or Private explicitly (Line #1).
  2. Wherever possible, declare your variables explicitly (Lines #2 & #3).
  3. Avoid use of numbered indices with collections (Line #4). It is harder to read, less obvious what the code is doing.
  4. Use indentation. This helps a reader to make sense of what your code is doing.

A revised version of your code below to illustrate these points :
Expand|Select|Wrap|Line Numbers
  1. Public Sub UpdateMDB()
  2.     Dim cn As ADODB.Connection
  3.     Dim rs As ADODB.Recordset
  4.  
  5.     strFile = ActiveWorkbook.FullName
  6.     strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile & _
  7.              ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
  8.     Set cn = CreateObject("ADODB.Connection")
  9.     Set rs = CreateObject("ADODB.Recordset")
  10.     cn.Open strCon
  11.     strSQL = "SELECT * FROM [Sheet1$] s " & _
  12.              "INNER JOIN [;Database=D:\temp excel\T.mdb;].Table1 t " & _
  13.              "ON s.id=t.id " & _
  14.              "WHERE s.Field1<>t.Field1"
  15.     rs.Open strSQL, cn, 1, 3
  16.     strSQL = "UPDATE [;Database=D:\temp excel\T.mdb;].Table1 t " & _
  17.              "INNER JOIN [Sheet1$] s " & _
  18.              "ON s.id=t.id " & _
  19.              "SET t.Field1=s.Field1 " & _
  20.              "WHERE s.Field1<>t.Field1 "
  21.     cn.Execute strSQL
  22. End Sub
To handle new records added to the Excel sheet, consider changing the last SQL to start with [Sheet1$] then use a LEFT JOIN to match up with [Table1]. If ADODB supports OUTER JOINs (SQL Server does but I don't think you can with Jet) then use that instead, and you can handle deleted records too.
Jun 29 '10 #4
NeoPa
32,556 Recognized Expert Moderator MVP
Sorry.

Forget the last suggestion. I overlooked the point that it was an UPDATE query. You can only update existing records. Separate INSERT and DELETE queries would be required to do the job completely.
Jun 29 '10 #5
anand padia
7 New Member
@NeoPa
Thanks will try that. However when in terms of going for a separate INSERT and DELETE queries I know how to do that individual, but how to compare it with existing records on excel.
Jun 29 '10 #6
NeoPa
32,556 Recognized Expert Moderator MVP
I presume you would INSERT any records that are in your workbook, but not already in [Table1]. DELETE should be for those records which are currently in [Table1] but which aren't in your workbook.
Jun 29 '10 #7
anand padia
7 New Member
@NeoPa
Yes you are absolutely right. Do you think it can be done...
Jun 29 '10 #8
thelonelyghost
109 New Member
There's no chance of running a small SQL server of sorts? What about attaching it to an existing server? If you are using an MDB file, they are definitely not made to be used by multiple users at the same time, whereas SQL tables are.

EDIT: I retract this statement of multiple concurrent users not being a part of MDB files. See post below

Also, if you go the route of SQL, this would save a lot of effort on your part in designing it and make it more versatile in what it can update. For instance, if you decide to move the employee records to some global corporate database (which could use Oracle, SQL server, etc.), it's just a nip and a tuck to do so with this. With your method it seems like it would take a total body reconstruction.
Jun 29 '10 #9
NeoPa
32,556 Recognized Expert Moderator MVP
thelonelyghost: If you are using an MDB file, they are definitely not made to be used by multiple users at the same time, whereas SQL tables are.
While Access databases are not able to handle multiple concurrent users as well as full, server based, solutions are, they are nevertheless, designed to handle multiple concurrent users. You may certainly find that the practical limit can be exceeded well before something like SQL Server, but that is some way short of meaning multiple users are not handled. It does depend on correct configuration for them of course.
Jun 30 '10 #10
NeoPa
32,556 Recognized Expert Moderator MVP
anand padia: Yes you are absolutely right. Do you think it can be done...
I see no reason why not, assuming you have a clear understanding of exactly what you're hoping to do with it.
Jun 30 '10 #11
thelonelyghost
109 New Member
@NeoPa
You're right. That was my mistake. I revisited my source for that bit of information and it said something like 20 users max (depending on what you're doing), which was significantly less than what I needed. I therefore wrote it off as useless for multiple concurrent users in favor of something most bigger corporations have and use: SQL Server (or the like). Once again, my bad and I recant my previous statement.
Jun 30 '10 #12
NeoPa
32,556 Recognized Expert Moderator MVP
No fuss :)

Like you, I wouldn't consider it for a big, concurrent multi-user project, but there is some limited scope there. This can be important for small office concerns where they are nervous of investing time and/or money into two different systems. Unfortunately, most such users struggle with configuring it correctly for concurrent multi-use anyway :(
Jun 30 '10 #13

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

Similar topics

6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
1
by: john_liu | last post by:
How can I update an Access table based on a sheet in Excel by VBA in excel. Thanks
2
by: info | last post by:
I can successfully open a recordset based upon an Excel sheet in Access, but I can't work out how to copy all the records to an Access table. Any pointers?
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...
2
by: ruthboaz | last post by:
Hi, I am exporting a table with data to an excel file.. Some fields are empty in the exported file while the others and the key field, has values. The empty field(s) in excel, will be entered...
2
by: jalmar | last post by:
Hello....I'm back again with the same question. I still haven't been able to figure out why my query isn't working. I am linking a table to an Excel spreadsheet, that part is fine, it is even...
4
by: christianlott1 | last post by:
I've linked an excel worksheet as an access table. The values appear but it won't allow me to change any of the values. To test I've provided a fresh blank workbook and same problem. I've done...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.