Results 1 to 12 of 12

update table in access from excel using sql

Threaded View

  1. #1
    Registered User
    Join Date
    02-14-2013
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    55

    update table in access from excel using sql

    Hello,

    I would like to update a table in access using a sql statement in Excel. I am not overly familiar with SQL and am getting a syntax error when trying to update. Any feedback is appreciated. The full SQL statement is as follows: UPDATE tbl_RETRO_EFF_76_PREV_WK AS t1 INNERJOIN tablec AS t2 ON t1.NUMBER = t2.NUMBER set COMPLETED =True, DATE =3/17/2014, NTID =Mike;
    Option Explicit
    Sub test()
    
    Dim acApp As Object
    Dim sqlString As String
    Dim dbs As Database
    Dim ws As Worksheet
    Dim wsn As String
    Dim c As Range
    Dim tn As String
    Dim rng As Range
    
    wsn = Range("wsName").Value
    tn = Range("tblName").Value
    
    Set acApp = CreateObject("Access.Application")
    Set rng = Application.Range(tn & "[completed]")
    
    
    Worksheets(wsn).Activate
    
    For Each c In rng
        If c.Value = True Then
            sqlString = "UPDATE tbl_RETRO_EFF_76_PREV_WK AS t1 INNERJOIN tablec AS t2 ON t1.NUMBER = t2.NUMBER set"
            sqlString = sqlString & " COMPLETED =" & c.Value & ","
            sqlString = sqlString & " DATE =" & c.Offset(0, -1).Value & ","
            sqlString = sqlString & " NTID =" & c.Offset(0, -2).Value & ";"
            
            Debug.Print sqlString
            
           
            With acApp
            Set dbs = OpenDatabase("mylocation")
            With dbs
            .Execute sqlString, dbFailOnError
            .Close
            End With
            Set dbs = Nothing
            End With
        Else
        End If
    
    Next
    
    End Sub
    Last edited by Leith Ross; 03-18-2014 at 11:10 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How do I Update Specific Access 2007 Table Fields Using Excel 2007 Macro?
    By anton20 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-05-2014, 02:49 PM
  2. Update Access Table from Excel using DAO
    By vish2025 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-15-2010, 06:02 AM
  3. Update & Append Access Table Using Excel Macro - ADO
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-19-2010, 04:49 AM
  4. VBA to update cells with data from Microsoft Access table
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2009, 07:31 AM
  5. Replies: 0
    Last Post: 06-24-2005, 05:05 PM

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