Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit .mdb Database from Excel

Status
Not open for further replies.

ssVBAdev

Programmer
May 23, 2003
257
US
Seems I'm more of a questioner lately rather then a helper... But, I've got another question.

I have an .mdb database that I am able to open from excel (OpenDatabase), extract the data I need and enter into an excel spreadsheet in a format that is easy to understand.

Fine.

But I want to be able to "correct" or edit some of that data from my "user friendly" GUI I've setup in excel and send that back to the .mdb database.

I wouldn't be adding any records, simply overwriting some of the data of some of the records.

Something like this pseudo code:
Code:
If .cells(Row, 1).Value = Record Then
   If .cells(Row, 2).Value <> Data1 Then Overwrite Data
   If .cells(Row, 3).Value <> Data2 Then Overwrite Data
   .
   .
   .

End If

Following?? Am I explaining myself correctly??

It's the &quot;Overwrite Data&quot; part that I am not sure about. The rest of the code around it is a breeze, but I just don't know how to see if Data in the Record matches my Excel data and if it does not, then how do I overwrite it?

********************
What's the best way to get the answers you need?? See FAQ222-2244 for details!
 
Hi ssVBAdev,

What you are describing is an UPDATE query.

Set a reference in VB Editor to Microsoft ActiveX Data Objects x.y Library. (the most recent)

You are going to have to set an ADO recordset object and a connect object to you database. Your recordset object needs to be updateable, probably a Table-Type recordset.

Look at the Help examples. Code and example and see how it works.

You will have to have your table cursor positioned on the correct record to do the Update. Key values cannot be Updated.

Good luck! It will be a learning expertince. Poat back with your questions.

:)



Skip,
Skip@TheOfficeExperts.com
 
HMM...

Doesn't sound as simple as I thought. Getting the data from the database was simple. I guess I thought it'd be simple to &quot;put it back&quot; also.

And Yes, I'm sure it'll be a learning experience. I'll try to post back if I find anything relatively soon.

Anyone else have any thought's that might lead me in the right direction...

********************
What's the best way to get the answers you need?? See FAQ222-2244 for details!
 
Hey!! That'd be great! I appreciate that Skip. Won't get to see 'em until tomorrow though... day's almost done and my finger is hovering precariously above the Shut Down button... (manner of speaking of course).

********************
What's the best way to get the answers you need?? See FAQ222-2244 for details!
 
OH BABY!!!

I've got it working and man-o-man does it ever work slick!! Well, that is to say that I have the backbone working; I'll need to &quot;dress it up&quot; a little.

A little caveat here... I'm not a database expert by any means and, in fact, this is my first try at a &quot;real&quot;, usable database app... but here goes...

I used &quot;transaction&quot; (BeginTrans, CommitTrans, Rollback) to transfer the data from Excel to the Database.

Make sure you have Microsoft DAO 3.6 Object Library in your references.

I simply go through each record of the database,
Code:
Do While Not .EOF
and
Code:
.MoveNext

test if it meets a certain critera, finds the data in the excel spreadsheet that it needs and use the .edit and .update methods to transfer the data.
Code:
.Edit
!quan = Worksheets(&quot;Assembly&quot;).Cells(Row, Col).Value
.Update
WOO HOO!!

Thanks for the help though Skip!

********************
What's the best way to get the answers you need?? See FAQ222-2244 for details!
 
I guess my exuberance showed through huh :)

********************
What's the best way to get the answers you need?? See FAQ222-2244 for details!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top