简体   繁体   English

Excel VBA 抛出 ODBC

[英]Excel VBA throwing an ODBC

I'm getting a "General ODBC error" every time I run this.每次运行此程序时,我都会收到“常规 ODBC 错误”。 Is there something incorrect with my syntax?我的语法有什么不正确的吗? What does this seem to be telling me?这似乎在告诉我什么? When I do ?ssql and copy it into SQL Server, it runs.当我执行 ?ssql 并将其复制到 SQL Server 时,它会运行。

Thank you :) The below is the simple code that I have entered.谢谢 :) 下面是我输入的简单代码。

sSQL = "select " & _
"CompanyName" & _
",FirstName" & _
",LastName" & _
",FullName" & _
",Subject Topic" & _
",OwnerIdName" & _
",A.CreatedOn" & _
",EMailAddress1" & _
",JobTitle" & _
",Value  Status " & _
" from Lead  A " & _
"left join   MSCRM.dbo.StringMap E on   New_LeadStatus = E.AttributeValue And E.AttributeName = 'new_leadstatus' " & _
"where CreatedOn > getdate() - (7)"




With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "ODBC;DSN=test;UID=test;PWD=test;APP=2007 Microsoft Office system;DATABASE=MSCRM;" _
        , Destination:=Range("$A4")).QueryTable
        .CommandText = sSQL
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "Query_from_CRMDB"
        .Refresh BackgroundQuery:=False
    End With

Call AutoFmt
    
Sheets(ActiveSheet.Name).Name = "Lead Report"
    
Cells(1, 1).Select

The reason why I had this was because my computer did not have an ODBC connection to the new database.我有这个的原因是因为我的计算机没有到新数据库的 ODBC 连接。 This is now solved.现在已经解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM