gpt4 book ai didi

vba - 如何在 VBA 中插入 TEMP 表

转载 作者:行者123 更新时间:2023-12-04 19:51:20 25 4
gpt4 key购买 nike

当我运行以下代码时,我收到错误消息“运行时错误‘1004’:应用程序定义或对象定义的错误”

当我选择调试时,会突出显示以下行:.Refresh BackgroundQuery:=False

querystr = "SET NOCOUNT ON" & Chr(13) & _
"SELECT CSD.StoreNo AS 'StoreNo',SUM(CSD.Amount) as totalSales " & Chr(13) & _
"INTO #SalesOfTheStores " & Chr(13) & _
"FROM Purchase.dbo.CashsheetDetail as CSD " & Chr(13) & _
"INNER JOIN Purchase.dbo.CashsheetHeader as CSH on CSH.TransferID = CSD.TransferID and CSH.StoreNo = CSD.StoreNo " & Chr(13) & _
"WHERE CSD.Comments = 'Total Gross Sales' AND CSH.DayendDate between '" & StartDate & "' And '" & EndDate & "' " & Chr(13) & _
"GROUP BY CSD.StoreNo; "



With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=" & Div & "DBL01\SR;UID=" & User & ";APP=Microsoft Office 2003;WSID=" & PC & ";DATABASE=Purchase;Trusted_Connection=Yes" _
, Destination:=Range("A1"))
.RefreshStyle = xlOverwriteCells
.CommandText = querystr
.Refresh BackgroundQuery:=False

结束于

最佳答案

您的查询字符串不返回数据。将您的 SQL 更改为 SELECT 语句而不是 SELECT INTO(删除 INTO 子句)。

关于vba - 如何在 VBA 中插入 TEMP 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27238294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com