+ Reply to Thread
Results 1 to 6 of 6

Update Access 2003 records using Excel 2003 via macro

  1. #1
    Registered User
    Join Date
    05-17-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Update Access 2003 records using Excel 2003 via macro

    Hi everyone,

    I have a Access2003 database (c:\db\testdb.mdb) contains a table(product) with product numbers (CSPC) and prices (Price) and some other fields.

    An Excel2003 file (c:\db\priceUpdate.xls) includes a worksheet (NewPrice). There are two columns (CSPC and Price in the worksheet, and start from row 2).

    I want to use the Excel prices to update the Access prices; but I don't know how to to code the macro. Can anyone help me out on this issue?

    Thank you in advance.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Update Access 2003 records using Excel 2003 via macro

    I suspect it may be simpler to set the worksheet up as a linked table in Access and then run an update query joining the two tables.
    Remember what the dormouse said
    Feed your head

  3. #3
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Update Access 2003 records using Excel 2003 via macro

    try something like this
    Please Login or Register  to view this content.
    this will add just the one line of data into the access database, so you may need to do a loop
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  4. #4
    Registered User
    Join Date
    05-17-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Update Access 2003 records using Excel 2003 via macro

    @Sean Thomas:
    I got a "compiler error: User-defined type not defined" @ line 4 "Dim Command As ADODB.Command".
    What would be the cause?

    @romperstomper:
    I think your solution is one of the easiest way to solve this issue. But I want to learn how to work it out and update multiple tables as well. Thank you for your respond.

  5. #5
    Registered User
    Join Date
    05-17-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Update Access 2003 records using Excel 2003 via macro

    @Sean Thomas:
    I solve the compiler error.
    I changed the INSERT statement to:
    CommandText = _
    "UPDATE product" & _
    "SET product.price = '" & Sheets("NewPrice").Range("B2").Value & "'" & _
    "WHERE product.cspc = '" & Sheets("NewPrice").Range("A2").Value & "';"
    It prompts up "Error executing UPDATE statement."

  6. #6
    Registered User
    Join Date
    05-17-2014
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Update Access 2003 records using Excel 2003 via macro

    @Sean Thomas:
    Problem solved. Just miss a space after the table name.
    Thank you very much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Update records to Access 97 from Excel 97 via macro
    By kennethqiu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-03-2014, 05:47 PM
  2. [SOLVED] Recover Accidentally Deleted RECORDS of a Table in Ms-Access 2003
    By :) Sixthsense :) in forum Access Tables & Databases
    Replies: 5
    Last Post: 04-30-2014, 01:38 PM
  3. [SOLVED] Excel/Access update records
    By Raanan in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-19-2014, 05:14 AM
  4. Excel 2007 VBA code to update linked-tables in Access 2003
    By armensg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-30-2013, 12:45 PM
  5. Excel 2003 not understanding Access 2003 "like"
    By Martin in forum Excel General
    Replies: 0
    Last Post: 11-04-2005, 08:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1