?
Solved

Update Access DB from Excel Sheet

Posted on 2011-10-10
6
Medium Priority
?
190 Views
Last Modified: 2012-05-12
Hey Experts!!

I have a slight problem and I'm really hoping someone can help me.  About a month ago, I exported a query (below) from an Access 2003 DB to Excel. People have been updating it with newer values.

What I need to do now is update the same 3 tables with the updated information from an Excel sheet.  I'm not sure how to go about doing that though. Do I use an "UPDATE" instead of "SELECT" statement? Do I do each table individually?  

Thanks in advance.
SELECT DISTINCT Client.ACT_no, Client.Client, Client.Address, Client.Address2, Client.City, Client.State, Client.Zipplus, Client.County, Client.AREA_Phone, Client.CatSub_ID, Client.Contact_no, Client.notes_id, Client.script, Client.instructor, Client.instructor_phone, Client.user_main, Client.last_user, Client.last_date, Contacts.*, Cat_Sub.*
FROM (Contacts RIGHT JOIN Client ON Contacts.ACT_No = Client.ACT_no) LEFT JOIN Cat_Sub ON Client.CatSub_ID = Cat_Sub.CatSub_ID;

Open in new window

0
Comment
Question by:LZ1
  • 3
  • 3
6 Comments
 
LVL 85
ID: 36942862
If you're not adding new records to those tables, then yes, you'd use an UPDATE statement. The basic syntax is this:

UPDATE YourTable SET Field1=Value1, Field2=Value2 WHERE YourPrimaryKeyField=PrimaryKeyValue

Of course, you'll be grabbing this data from the worksheet, so it would look something like this:

YourConnection.Execute "UPDATE YourTable SET Field1='" & Cells("A1") & "', Field2=#" & Cells("B1") & "# WHERE YourPrimaryKeyField=" & YourPrimaryKeyValue

My Excel syntax might be rusty, but hopefully that will give you the gist of what to do.

Also, you would need to update each table individually. If you are ADDING records, and if those tables are related, they would need to be done in order - in other words, you'd have to add the Parent records before the Child records.

Note also the syntax in the statement above. Access expects Text value to be surrounded in single or double quotes, and expects Date values to be surrounded with hash marks ( # ). In my example above, Field1 is a Text field, and I've surrounded the value for that field with single quotes. Field2 is a Date field, and I've surrounded the values for that field with hash marks.

0
 
LVL 30

Author Comment

by:LZ1
ID: 36942872
Hi LSMConsulting. Yes, it's just updating as far as I'm aware but I will verify with the client. So for the Excel sheet, how would I call the file inside the query syntax?
0
 
LVL 85
ID: 36942880
What do you mean "call the file"?

Are you running this in Excel or Access?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 30

Author Comment

by:LZ1
ID: 36942887
The query will be running in Access, as that's where the tables are. But how do I import(for lack of a better term) all of the updated fields?
0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 36942897
Sorry ... it seems that you have an external worksheet, and you need to now update the values in access based on those new values.

Is this a "one time" thing - that is, you'll update this now, and won't have to do it again (or won't do it again for quite some time), or is this an on-going update process?

If it's a one time thing, the simplest way would be to simply Import that Excel worksheet into Access, then use standard VBA processes to get to the data in the (now imported) table. In fact, you may be able to do this entirely with the query designer, depending on the structure of the incoming data.
0
 
LVL 30

Author Comment

by:LZ1
ID: 36942954
This will be a one time thing LSMConsulting. However, I'd much rather hand code it if I can.  I suppose I could use the query designer though. The structure of the data should be good though.

So my steps, as I understand you, should be this:
1) Import my Excel sheet into a whole new table and name it
2) Then using an UPDATE Syntax, run the same query as the SELECT statement and reference that new table.
3) I should be done???
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question