Results 1 to 5 of 5

A Classic Run-Time 1004

Threaded View

  1. #1
    Registered User
    Join Date
    12-18-2009
    Location
    Leeds
    MS-Off Ver
    Excel 2003
    Posts
    5

    A Classic Run-Time 1004

    I have a bit of VBA which updates connections in a workbook to a new server and/or database name, which you can then update all the tables with. It is useful because I have a lot of SQL linked tables, which would take a lot of time to update manually.

    Before anyone says I should use PowerPivot, I'll say that I tried, and unfortunately it regularly crashed or threw up errors. This way works. Sort of...

    So, the problem is that at the moment it seems to be throwing a 1004 error, though I'm sure it has been working in the past. A

    Here is the code:

    Sub UpdateAllConnections()
        Dim Server As String, Database As String, IntegratedSecurity As Boolean, UserId As String, Password As String
        Dim ConnectionString As String
        Dim MsgTitle As String
        Dim cn As WorkbookConnection
        
        MsgTitle = "Connection Update"
    
        If vbOK = MsgBox("Go grab your copy & paste brush!", vbOKCancel, MsgTitle) Then
            Server = InputBox("Database server & instance name", MsgTitle)
            If Server = "" Then GoTo Cancelled
            Database = InputBox("Database name", MsgTitle, "Tesco_Reading_phase2")
            If Database = "" Then GoTo Cancelled
            End If
                    
            For Each cn In ActiveWorkbook.Connections
            
                cn.OLEDBConnection.Connection = "OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog = " & Database & ";Data Source=" & Server & ";Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=AHUNTER;Use Encryption for Data=False;Tag with column collation when possible=False;"
                
            Next cn
            
            MsgBox "Spreadsheet Updated", vbOKOnly, MsgTitle
        Exit Sub
    Cancelled:
        MsgBox "Connections not updated", vbOKOnly, MsgTitle
    End Sub
    cn.OLEDBConnection.Connection... etc is the error line.


    Any help would be very gratefully received!
    Last edited by AMCAlex; 07-08-2013 at 06:49 AM. Reason: Clarification

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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