2012-07-19 61 views
2

我在Windows XP 32位計算機上創建了Microsoft Excel 2003中的宏,當我按下我的電子表格中的刷新按鈕時,它應該如此填充。Excel 2003中的工作代碼在Windows 7中拋出運行時錯誤

然而,當我的用戶計算機上運行該其是視窗7的機器,32位和64位I得到以下錯誤消息

「運行時錯誤‘2147467259(80004005)’: [微軟] [ODBC驅動程序管理器]未找到數據源名稱未指定默認驅動程序「

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 

回答

3

我在猜測您正在連接到SQL Server。在模糊連接字符串時,您已刪除可用於正確識別問題的任何信息。我懷疑你可能在其他PC上使用DSN,因爲你甚至沒有提供該字符串中的提供者。你可以在這裏獲得有關連接字符串的信息:http://www.connectionstrings.com/

相關問題