+ Reply to Thread
Results 1 to 7 of 7

Run-time error '-2147467259 (80004500)' - VBA for Access dbase update

Hybrid View

  1. #1
    Registered User
    Join Date
    10-20-2013
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    40

    Run-time error '-2147467259 (80004500)' - VBA for Access dbase update

    Hey guys,

    A little bit of how my set goes. First, I have an access database that stores the employee information as well as call metric goals. I use a VBA script to pull certain agents based on a few parameters into a table. What I need to happen is, if any data is changed in that same table, such as, an employees metric goal is adjusted, I need it to updated on the access database table. Here is the script I am using. I'm using Excel and Access 2013.

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rng As Range
        Dim r As Long
        Dim conn As ADODB.Connection
        Dim strConn As String
        Dim strSQL As String
    
        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
            "C:\Users\Josh\Desktop\agent-data-2014.accdb"
        Set conn = New ADODB.Connection
        conn.Open strConn
        For Each rng In Target.Rows
            r = rng.Row
            If r > 1 Then
                strSQL = "UPDATE MSC_MU SET " & _
                    "MU_ID='" & Worksheets("CONF").Range("F" & r).Value & "', " & _
                    "AGENT_NAME='" & Worksheets("CONF").Range("G" & r).Value & "', " & _
                    "AGENT_ID='" & Worksheets("CONF").Range("H" & r).Value & ", " & _
                    "CATEGORY='" & Worksheets("CONF").Range("I" & r).Value & "', " & _
                    "TEAM='" & Worksheets("CONF").Range("J" & r).Value & "', " & _
                    "SUPERVISOR='" & Worksheets("CONF").Range("K" & r).Value & "', " & _
                    "EMP_STATUS='" & Worksheets("CONF").Range("L" & r).Value & "', " & _
                    "TERM_DATE='" & Worksheets("CONF").Range("M" & r).Value & "', " & _
                    "DAYS='" & Worksheets("CONF").Range("N" & r).Value & "', " & _
                    "TIME='" & Worksheets("CONF").Range("O" & r).Value & "', " & _
                    "BREAKS='" & Worksheets("CONF").Range("P" & r).Value & "', " & _
                    "LUNCH='" & Worksheets("CONF").Range("Q" & r).Value & "', " & _
                    "CPH='" & Worksheets("CONF").Range("R" & r).Value & "', " & _
                    "RING='" & Worksheets("CONF").Range("S" & r).Value & "', " & _
                    "TALK='" & Worksheets("CONF").Range("T" & r).Value & "', " & _
                    "ACW='" & Worksheets("CONF").Range("U" & r).Value & "', " & _
                    "HOLD='" & Worksheets("CONF").Range("V" & r).Value & "', " & _
                    "UAUX='" & Worksheets("CONF").Range("W" & r).Value & "', " & _
                    "PAUX=" & Worksheets("CONF").Range("X" & r).Value & " WHERE " & _
                    "ID=" & Worksheets("CONF").Range("E" & r).Value
                conn.Execute strSQL
            End If
        Next rng
        conn.Close
        Set conn = Nothing
    End Sub
    Now, I get the feeling I'm using the wrong strConn/reference in this script, like it's looking for sql and not access library. When I change something in the table, I get this gnarly error message:

    Run-time error '-2147467259 (80004500)' Unrecognized database format.

    Any ideas why or what I can do to make this work?

  2. #2
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Run-time error '-2147467259 (80004500)' - VBA for Access dbase update

    Hi baijixu,

    Kindly check your connection string, you are using Jet OLEDB provider to connect to ACCDB file.
    Try to use the following connection string :

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=A:\AccessFile.accdb;
    Persist Security Info=False;


    You can check this link for further info :
    http://msdn.microsoft.com/en-us/library/cc280478.aspx


    Regards,
    Paresh J
    Last edited by pareshj; 06-07-2014 at 01:57 AM.
    Click on "* Add Reputation" as a way to say thanks

  3. #3
    Registered User
    Join Date
    10-20-2013
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    40

    Re: Run-time error '-2147467259 (80004500)' - VBA for Access dbase update

    This works:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rng As Range
        Dim r As Long
        Dim conn As ADODB.Connection
        Dim strConn As String
        Dim strSQL As String
    
        strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
            "C:\Users\Josh\Desktop\agent-data-2014.accdb"
    
            
        Set conn = New ADODB.Connection
        conn.Open strConn
        For Each rng In Target.Rows
            r = rng.Row
            If r > 1 Then
                strSQL = "UPDATE MSC_MU SET " & _
                    "MU_ID='" & Worksheets("SQL").Range("B" & r).Value & "', " & _
                    "AGENT_NAME='" & Worksheets("SQL").Range("C" & r).Value & "', " & _
                    "AGENT_ID='" & Worksheets("SQL").Range("D" & r).Value & "', " & _
                    "CATEGORY='" & Worksheets("SQL").Range("E" & r).Value & "', " & _
                    "TEAM='" & Worksheets("SQL").Range("F" & r).Value & "', " & _
                    "SUPERVISOR='" & Worksheets("SQL").Range("G" & r).Value & "', " & _
                    "EMP_STATUS='" & Worksheets("SQL").Range("H" & r).Value & "', " & _
                    "TERM_DATE='" & Worksheets("SQL").Range("I" & r).Value & "' WHERE " & _
                    "ID=" & Worksheets("SQL").Range("A" & r).Value
                conn.Execute strSQL
            End If
        Next rng
        conn.Close
        Set conn = Nothing
    End Sub
    However, is there a way to make this a button click-able macro that updates the entire table at once rather than have it update each time a field is changed?

  4. #4
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Run-time error '-2147467259 (80004500)' - VBA for Access dbase update

    Hi baijixu,

    Yes you can. Just follow the below steps :
    1) Select the sheet where you want to place the button.
    2) Go to Developer Tab > Insert > Under ActiveX Controls add CommandButton control on sheet.
    3) Then Just double click the commandbutton, it will open up VBE editor in order to place your VBA code.
    4) Just copy paste the code to CommandButton_Click function.

    Note : If you dont see Developer Tab on your menu,
    Go to Microsoft Office Icon at the Top left > Click Excel options > Under Popular option > Just check the "Show Developer Tab in the Ribbon" option.


    Regards,
    Paresh J

  5. #5
    Registered User
    Join Date
    10-20-2013
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    40

    Re: Run-time error '-2147467259 (80004500)' - VBA for Access dbase update

    Private Sub CommandButton1_Click()
        Dim rng As Range
        Dim r As Long
        Dim conn As ADODB.Connection
        Dim strConn As String
        Dim strSQL As String
    
        strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
            "C:\Users\Josh\Desktop\agent-data-2014.accdb"
    
            
        Set conn = New ADODB.Connection
        conn.Open strConn
        For Each rng In Target.Rows
            r = rng.Row
            If r > 1 Then
                strSQL = "UPDATE MSC_MU SET " & _
                    "MU_ID='" & Worksheets("CONF").Range("F" & r).Value & "', " & _
                    "AGENT_NAME='" & Worksheets("CONF").Range("G" & r).Value & "', " & _
                    "AGENT_ID='" & Worksheets("CONF").Range("H" & r).Value & "', " & _
                    "CATEGORY='" & Worksheets("CONF").Range("I" & r).Value & "', " & _
                    "TEAM='" & Worksheets("CONF").Range("J" & r).Value & "', " & _
                    "SUPERVISOR='" & Worksheets("CONF").Range("K" & r).Value & "', " & _
                    "EMP_STATUS='" & Worksheets("CONF").Range("L" & r).Value & "', " & _
                    "TERM_DATE='" & Worksheets("CONF").Range("M" & r).Value & "' WHERE " & _
                    "ID=" & Worksheets("CONF").Range("E" & r).Value
                conn.Execute strSQL
            End If
        Next rng
        conn.Close
        Set conn = Nothing
    End Sub
    Okay I have added the button and the code. I edited some fields and clicked the button and got this error:
    "Run-time error '424' Object Required" and the debug is highlighting For Each rng In Target.Rows

  6. #6
    Registered User
    Join Date
    10-20-2013
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    40

    Re: Run-time error '-2147467259 (80004500)' - VBA for Access dbase update

    Pareshj, you have been a huge help and I thank you! Honestly, I know very little of VBA and I've been at this for over 12 hours.

    Here is the script I am using now, it seems to be working!

    
    Private Sub CommandButton1_Click()
        Dim rng As Range
        Dim r As Long
        Dim conn As ADODB.Connection
        Dim strConn As String
        Dim strSQL As String
    
        strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
            "C:\Users\Josh\Desktop\agent-data-2014.accdb"
    
            
        Set conn = New ADODB.Connection
        conn.Open strConn
        'For Each rng In Target.Rows
        r = 8
        Do While Len(Range("E" & r).Formula) > 0
            If r > 1 Then
                strSQL = "UPDATE MSC_MU SET " & _
                    "MU_ID='" & Worksheets("CONF").Range("F" & r).Value & "', " & _
                    "AGENT_NAME='" & Worksheets("CONF").Range("G" & r).Value & "', " & _
                    "AGENT_ID='" & Worksheets("CONF").Range("H" & r).Value & "', " & _
                    "CATEGORY='" & Worksheets("CONF").Range("I" & r).Value & "', " & _
                    "TEAM='" & Worksheets("CONF").Range("J" & r).Value & "', " & _
                    "SUPERVISOR='" & Worksheets("CONF").Range("K" & r).Value & "', " & _
                    "EMP_STATUS='" & Worksheets("CONF").Range("L" & r).Value & "', " & _
                    "TERM_DATE='" & Worksheets("CONF").Range("M" & r).Value & "' WHERE " & _
                    "ID=" & Worksheets("CONF").Range("E" & r).Value
                conn.Execute strSQL
            End If
            r = r + 1
            Loop
        conn.Close
        Set conn = Nothing
    End Sub

  7. #7
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Run-time error '-2147467259 (80004500)' - VBA for Access dbase update

    Hi,

    You need to define your Target range. Check the following code:

    Sub Worksheet_Change(ByVal Target As Range)

+ 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. Run time error'-2147467259(80004005)':
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2014, 12:27 AM
  2. run-time error '-2147467259(80004005)':
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-02-2014, 03:46 AM
  3. [SOLVED] Run-time error '-2147467259(80004005)'
    By Lloyd Blankfein in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-14-2013, 01:52 PM
  4. Excel 2010 Run Time Error '-2147467259 (80004005)'
    By jdpeterson72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2012, 06:52 PM
  5. Run time error '-2147467259 (80004005) adding icon
    By DMc2005 in forum Excel General
    Replies: 3
    Last Post: 10-02-2005, 12: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