2
votes

I have created the macro below in Microsoft Excel 2003 on a windows XP 32 bit machine, when I press the refresh button my spreadsheet populates as it should.

However when I run this on the users machine which are windows 7 machines, both 32 bit and 64 bit i get the following error message

"Run-time error '-2147467259 (80004005)': [Microsoft][ODBC Driver Manager] Data source name not found an no default driver specified"

Private Sub CommandButton1_Click()
    Dim cmd As New ADODB.Command
    Dim conn As ADODB.Connection
    Dim prm As ADODB.Parameter
    Dim strConn As String
    Dim strSQL As String
    Dim Rst As ADODB.Recordset
    Dim WSP As Worksheet
    Dim lastRow As Long
    Dim ranges As range



 strConn = "Data Source=;Initial Catalog=;User Id=;Trusted_Connection=False;"
    Set conn = New ADODB.Connection
    Set WSP = Worksheets("KPI")

    lastRow = WSP.Cells.SpecialCells(xlCellTypeLastCell).Row
    Set ranges = WSP.range("A6", WSP.Cells(lastRow, "K"))
    ranges.Clear

    conn.Open strConn

    Set cmd = New ADODB.Command
    cmd.CommandText = "dbo.returns_kpi_data"
    cmd.CommandType = adCmdStoredProc
    cmd.ActiveConnection = conn

    cmd.Parameters.Refresh
    cmd.Parameters("@OrderDate1").Value = WSP.range("G3", "G3")
    cmd.Parameters("@OrderDate2").Value = WSP.range("I3", "I3")


    'Execute the Stored Procedure
    Set Rst = cmd.Execute

    range("A6").CopyFromRecordset Rst


    'Close the connection
    conn.Close
End Sub
1

1 Answers

3
votes

I am guessing that you are connecting to SQL Server. In obfuscating the connection string, you have removed any information that could be used to properly identify the problem. I suspect that you may be using a DSN on the other PCs because you do not even have a provider in that string. You can get information on connection strings here: http://www.connectionstrings.com/