- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因此,我为其他报告运行了同样的宏,但由于某种原因,当我运行这个报告时,我收到了一个错误:
Run-Time Error 3704 Operation is not allowed when the object is closed
当我调试时它会突出显示这一点:
ThisWorkbook.Sheets("Sheet2").Range("A2").CopyFromRecordset rs
来 self 的宏:
Sub Bucket()
Dim cnn As New ADODB.Connection
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim cmd As New ADODB.Command
Dim ConnectionString As String
Dim StrQuery As String
strSort = ThisWorkbook.Sheets("Bucket").Cells(2, "A").Value
'ConnectionString = "Provider=SQLOLEDB;" & _
'"Data Source=RFCHaux01\sqlexpress;" & _
'"Initial Catalog=Monthly;" & _
'"Trusted_connection=yes;"
ConnectionString = "Driver={SQL Server Native Client 11.0};Server=RFCHaux01\sqlexpress;Database=Monthly;Trusted_Connection=yes"
cnn.ConnectionTimeout = 0
cnn.CommandTimeout = 0
cnn.Open ConnectionString
'rs.ActiveConnection = cnn
StrQuery = "if exists (select * from tempdb.sys.tables where name like '#check%') drop table #check if exists (select * from tempdb.sys.tables where name like '#check2%') drop table #check2 if exists (select * from tempdb.sys.tables where name like '#finaldata%') drop table #finaldata " & _
"select i.fileno, i.code, substring(i.field,0,5) + substring(i.field,6,2) as 'FILED_MONTH', dense_rank() over(partition by i.fileno order by i.date desc, i.field desc) as 'GARN_GOAL_CHECK', " & _
"row_number() over(partition by i.fileno order by i.date desc, i.code desc) as 'row_check', " & _
"c.court_id, convert(char(2), month(m.date_recd),100) + '/' + convert(char(4),year(m.date_recd),100) as 'MONTH_RECD', m.closed_yy, " & _
"case when m.jmt_amt is null then m.suit_amt else m.jmt_amt end as 'PLACED_AMT' " & _
"into #check from master m join masforw mf on mf.forw_no = m.forw_no join clerkf c on c.venue_no = m.venue1_no join infinity i on i.fileno = m.fileno " & _
"where (i.code in ('*WRT1DT', '*WRT2DT', '*WGRMLD', '*WgGarDT')) " & _
"select i.fileno, i.code, substring(i.field,0,5) + substring(i.field,6,2) as 'FILED_MONTH', " & _
"dense_rank() over(partition by i.fileno order by i.date desc, i.field desc) as 'GARN_GOAL_CHECK', " & _
"row_number() over(partition by i.fileno order by i.date desc, i.code desc) as 'row_check', c.court_id, " & _
"convert(char(2),month(m.date_recd),100) + '/' + convert(char(4),year(m.date_recd),100) as 'MONTH_RECD', " & _
"m.closed_yy, case when m.jmt_amt is null then m.suit_amt else m.jmt_amt end as 'PLACED_AMT' " & _
"into #check2 from master m join masforw mf on mf.forw_no = m.forw_no join clerkf c on c.venue_no = m.venue1_no " & _
"join infinity i on i.fileno = m.fileno where (i.code in ('*WRT3DT','*WRT4DT','*BGRMLD')) " & _
"select distinct m.fileno as 'File Number', mf.sort_field as 'sort field', m.forw_no as 'Port', inside.amt_recvd, inside.trans_date, case when m.Source <> 'HISTORY\HISTORY' then 'Open' else 'Close' end as 'Status', ii4.field as 'Pooltype', " & _
"m.forw_refno as 'Unifund File Number', m.orig_claim as 'Original Amount', d.st as 'Debtor State', c.cnty_name as 'County Filed In', m.date_recd as 'Recieved Date', m.suit_date as 'Suit Date', m.jmt_date as 'Judgement Date', " & _
"m.statute_date as 'Statute of Limitation Date', Convert(VARCHAR(50),Convert(Datetime, i.field),101) as 'Suit to Court', Convert(VARCHAR(50),Convert(Datetime, i1.field),101) as 'Resent for Service', Convert(VARCHAR(50),Convert(Datetime, ii1.field),101) as 'Served', " & _
"i2.field as 'Suit Worthiness', i3.field as 'SW Type', d.fico_score as 'Credit Score', i4.field as 'Triple Match', i5.field as 'Place Status', i6.field as 'Prior Status', case when g.code = '*WGRMLD' then 'GARN' when g.code = '*WgGarDT' then 'GARN' " & _
"when g.code = '*WRT1DT' then 'GARN' when g.code = '*WRT2DT' then 'GARN' else '' end as 'Garn', case when g2.code = '*BGRMLD' then 'LEVY' when g2.code = '*WRT3DT' then 'LEVY' when g2.code = '*WRT4DT' then 'LEVY' else '' end as 'LEVY', i7.field as 'Verification Date 1', i9.field as 'Verification Of', i8.field as 'Verification Date 2', ii.field as 'Verification', m.charge_off_date, ii2.field as 'Grade', ii3.field as 'Grade D Overages', (m.int_coll + m.cost_recovered + m.prin_coll) as 'Collected' into #finaldata from master m left join(SELECT c1.fileno, c1.amt_recvd, c1.trans_date FROM colbills C1 WHERE trans_date = (SELECT MIN(trans_date) FROM colbills c2 where c1.FILENO = c2.FILENO AND c2.amt_recvd > 0 AND c2.amt_recvd IS NOT NULL)and AMT_RECVD = (select top 1 amt_recvd from colbills " & _
"where c1.fileno = fileno) and c1.AMT_RECVD > 0 group by c1.fileno, c1.AMT_RECVD, c1.TRANS_DATE) inside on inside.fileno = m.FILENO join masforw mf on mf.forw_no = m.forw_no join debtor d on d.fileno = m.fileno and d.number = 1 join clerkf c on c.venue_no = m.venue1_no left join infinity i on i.fileno = m.fileno and i.code = '*SCTOCT' left join infinity ii4 on ii4.fileno = m.fileno and ii4.code = '*AssetTp' left join infinity i1 on i1.fileno = m.fileno and i1.code = '*SCRSDT' left join infinity i2 on i2.fileno = m.fileno and i2.code = '*SUITREC' left join infinity i3 on i3.fileno = m.fileno and i3.code = '*SRVWFTY' left join infinity i4 on i4.fileno = m.fileno and i4.code = '*ADDMTCH' left join infinity i5 on i5.fileno = m.fileno and i5.code = '*FWCTYPE' left join infinity i6 on i6.fileno = m.fileno and i6.code = '*PRSTCOD' left join infinity i7 on i7.fileno = m.fileno and i7.code = '*PLVpD1' left join infinity i9 on i9.fileno = m.fileno and i9.code = '*PLVPN1' " & _
"left join infinity ii on ii.fileno = m.fileno and ii.code = '*PLVPN2' left join infinity i8 on i8.fileno = m.fileno and i8.code = '*PLVpD2' left join infinity ii1 on ii1.fileno = m.fileno and ii1.code = '*AMDTSV' left join infinity ii2 on ii2.fileno = m.fileno and ii2.code = '*SuitGrd' left join infinity ii3 on ii3.fileno = m.fileno and ii3.code = '*RiskGrd' left join #check g on g.fileno = m.fileno left join #check2 g2 on g2.fileno = m.fileno where (mf.sort_field = '" & strSort & "') and (m.fileno not like 'Z%' and m.fileno not like 'FOW%' ) " & _
"select f.* from #finaldata f where f.[Prior Status] <> 'RENEWED' or f.[Prior Status] is null " & _
"drop table #check drop table #check2 drop table #finaldata "
rs.Open StrQuery, cnn
ThisWorkbook.Sheets("Sheet2").Range("A2").CopyFromRecordset rs
End Sub
我假设这可能是因为记录集?也许我的查询太复杂,所以在发生任何事情之前就超时了?
我在某处读到,当查询如此大时,我必须执行 DoEvents
或 For
循环来保持连接打开直到完全执行,但我不知道。
非常感谢任何建议。
最佳答案
因为您有多个操作查询,包括使用临时表。考虑在 SQL Server 数据库内构建一个存储过程,然后使用 ADO Command 从 Excel 调用它。 .
SQL (strSort 不再连接,而是绑定(bind)到 @param 占位符)
CREATE PROCEDURE myStoredProcedure @param VARCHAR(50)
AS
BEGIN
SET NOCOUNT ON;
if exists (select * from tempdb.sys.tables where name like '#check%')
drop table #check
if exists (select * from tempdb.sys.tables where name like '#check2%')
drop table #check2
if exists (select * from tempdb.sys.tables where name like '#finaldata%')
drop table #finaldata
select i.fileno, i.code, substring(i.field,0,5) + substring(i.field,6,2) as 'FILED_MONTH',
dense_rank() over(partition by i.fileno order by i.date desc, i.field desc) as 'GARN_GOAL_CHECK',
row_number() over(partition by i.fileno order by i.date desc, i.code desc) as 'row_check',
c.court_id, convert(char(2), month(m.date_recd),100) + '/' + convert(char(4),year(m.date_recd),100) as 'MONTH_RECD', m.closed_yy,
case when m.jmt_amt is null then m.suit_amt else m.jmt_amt end as 'PLACED_AMT'
into #check
from master m
join masforw mf on mf.forw_no = m.forw_no
join clerkf c on c.venue_no = m.venue1_no
join infinity i on i.fileno = m.fileno
where (i.code in ('*WRT1DT', '*WRT2DT', '*WGRMLD', '*WgGarDT'))
select i.fileno, i.code, substring(i.field,0,5) + substring(i.field,6,2) as 'FILED_MONTH',
dense_rank() over(partition by i.fileno order by i.date desc, i.field desc) as 'GARN_GOAL_CHECK',
row_number() over(partition by i.fileno order by i.date desc, i.code desc) as 'row_check', c.court_id,
convert(char(2),month(m.date_recd),100) + '/' + convert(char(4),year(m.date_recd),100) as 'MONTH_RECD',
m.closed_yy, case when m.jmt_amt is null then m.suit_amt else m.jmt_amt end as 'PLACED_AMT'
into #check2
from master m
join masforw mf on mf.forw_no = m.forw_no
join clerkf c on c.venue_no = m.venue1_no
join infinity i on i.fileno = m.fileno
where (i.code in ('*WRT3DT','*WRT4DT','*BGRMLD'))
select distinct m.fileno as 'File Number', mf.sort_field as 'sort field', m.forw_no as 'Port',
inside.amt_recvd, inside.trans_date,
case when m.Source <> 'HISTORY\HISTORY' then 'Open' else 'Close' end as 'Status',
ii4.field as 'Pooltype', m.forw_refno as 'Unifund File Number', m.orig_claim as 'Original Amount',
d.st as 'Debtor State', c.cnty_name as 'County Filed In', m.date_recd as 'Recieved Date',
m.suit_date as 'Suit Date', m.jmt_date as 'Judgement Date',
m.statute_date as 'Statute of Limitation Date',
Convert(VARCHAR(50),Convert(Datetime, i.field),101) as 'Suit to Court',
Convert(VARCHAR(50),Convert(Datetime, i1.field),101) as 'Resent for Service',
Convert(VARCHAR(50),Convert(Datetime, ii1.field),101) as 'Served',
i2.field as 'Suit Worthiness', i3.field as 'SW Type', d.fico_score as 'Credit Score',
i4.field as 'Triple Match', i5.field as 'Place Status', i6.field as 'Prior Status',
case when g.code = '*WGRMLD' then 'GARN'
when g.code = '*WgGarDT' then 'GARN'
when g.code = '*WRT1DT' then 'GARN'
when g.code = '*WRT2DT' then 'GARN'
else '' end as 'Garn',
case when g2.code = '*BGRMLD'
then 'LEVY' when g2.code = '*WRT3DT'
then 'LEVY' when g2.code = '*WRT4DT'
then 'LEVY' else '' end as 'LEVY', i7.field as 'Verification Date 1',
i9.field as 'Verification Of', i8.field as 'Verification Date 2',
ii.field as 'Verification', m.charge_off_date, ii2.field as 'Grade',
ii3.field as 'Grade D Overages', (m.int_coll + m.cost_recovered + m.prin_coll) as 'Collected'
into #finaldata
from master m
left join
(SELECT c1.fileno, c1.amt_recvd, c1.trans_date
FROM colbills C1
WHERE trans_date = (SELECT MIN(trans_date)
FROM colbills c2
where c1.FILENO = c2.FILENO
AND c2.amt_recvd > 0 AND c2.amt_recvd IS NOT NULL)
and AMT_RECVD = (select top 1 amt_recvd
from colbills
where c1.fileno = fileno)
and c1.AMT_RECVD > 0 group by c1.fileno, c1.AMT_RECVD, c1.TRANS_DATE) inside
on inside.fileno = m.FILENO
join masforw mf on mf.forw_no = m.forw_no
join debtor d on d.fileno = m.fileno and d.number = 1
join clerkf c on c.venue_no = m.venue1_no
left join infinity i on i.fileno = m.fileno and i.code = '*SCTOCT'
left join infinity ii4 on ii4.fileno = m.fileno and ii4.code = '*AssetTp'
left join infinity i1 on i1.fileno = m.fileno and i1.code = '*SCRSDT'
left join infinity i2 on i2.fileno = m.fileno and i2.code = '*SUITREC'
left join infinity i3 on i3.fileno = m.fileno and i3.code = '*SRVWFTY'
left join infinity i4 on i4.fileno = m.fileno and i4.code = '*ADDMTCH'
left join infinity i5 on i5.fileno = m.fileno and i5.code = '*FWCTYPE'
left join infinity i6 on i6.fileno = m.fileno and i6.code = '*PRSTCOD'
left join infinity i7 on i7.fileno = m.fileno and i7.code = '*PLVpD1' left join infinity i9 on i9.fileno = m.fileno and i9.code = '*PLVPN1'
left join infinity ii on ii.fileno = m.fileno and ii.code = '*PLVPN2'
left join infinity i8 on i8.fileno = m.fileno and i8.code = '*PLVpD2'
left join infinity ii1 on ii1.fileno = m.fileno and ii1.code = '*AMDTSV'
left join infinity ii2 on ii2.fileno = m.fileno and ii2.code = '*SuitGrd'
left join infinity ii3 on ii3.fileno = m.fileno and ii3.code = '*RiskGrd'
left join #check g on g.fileno = m.fileno
left join #check2 g2 on g2.fileno = m.fileno
where (mf.sort_field = @param)
and (m.fileno not like 'Z%' and m.fileno not like 'FOW%' )
select f.* from #finaldata f where f.[Prior Status] <> 'RENEWED' or f.[Prior Status] is null
GO
END
VBA
Dim cnn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As New ADODB.Command
Dim ConnectionString As String, StrSort As String, StrQuery As String
StrSort = ThisWorkbook.Sheets("Bucket").Cells(2, "A").Value
ConnectionString = "Driver={SQL Server Native Client 11.0};Server=RFCHaux01\sqlexpress;Database=Monthly;Trusted_Connection=yes"
cnn.ConnectionTimeout = 0
cnn.CommandTimeout = 0
cnn.Open ConnectionString
With cmd
.ActiveConnection = cnn
.CommandType = adCmdStoredProc
.CommandText = "[myStoredProcedure]"
.Parameters.Append .CreateParameter("@param", adVarChar, adParamInput, 255, StrSort)
End With
Set rs = cmd.Execute
ThisWorkbook.Sheets("Sheet2").Range("A2").CopyFromRecordset rs
rs.Close: cnn.Close
Set rs = Nothing: Set cmd = Nothing: Set cnn = Nothing
<小时/>
关于sql - 运行时错误 '3704' 关闭对象时不允许进行操作。 VBA 中的 SQL 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52319648/
我的一位教授给了我们一些考试练习题,其中一个问题类似于下面(伪代码): a.setColor(blue); b.setColor(red); a = b; b.setColor(purple); b
我似乎经常使用这个测试 if( object && object !== "null" && object !== "undefined" ){ doSomething(); } 在对象上,我
C# Object/object 是值类型还是引用类型? 我检查过它们可以保留引用,但是这个引用不能用于更改对象。 using System; class MyClass { public s
我在通过 AJAX 发送 json 时遇到问题。 var data = [{"name": "Will", "surname": "Smith", "age": "40"},{"name": "Wil
当我尝试访问我的 View 中的对象 {{result}} 时(我从 Express js 服务器发送该对象),它只显示 [object][object]有谁知道如何获取 JSON 格式的值吗? 这是
我有不同类型的数据(可能是字符串、整数......)。这是一个简单的例子: public static void main(String[] args) { before("one"); }
嗨,我是 json 和 javascript 的新手。 我在这个网站找到了使用json数据作为表格的方法。 我很好奇为什么当我尝试使用 json 数据作为表时,我得到 [Object,Object]
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我听别人说 null == object 比 object == null check 例如: void m1(Object obj ) { if(null == obj) // Is thi
Match 对象 提供了对正则表达式匹配的只读属性的访问。 说明 Match 对象只能通过 RegExp 对象的 Execute 方法来创建,该方法实际上返回了 Match 对象的集合。所有的
Class 对象 使用 Class 语句创建的对象。提供了对类的各种事件的访问。 说明 不允许显式地将一个变量声明为 Class 类型。在 VBScript 的上下文中,“类对象”一词指的是用
Folder 对象 提供对文件夹所有属性的访问。 说明 以下代码举例说明如何获得 Folder 对象并查看它的属性: Function ShowDateCreated(f
File 对象 提供对文件的所有属性的访问。 说明 以下代码举例说明如何获得一个 File 对象并查看它的属性: Function ShowDateCreated(fil
Drive 对象 提供对磁盘驱动器或网络共享的属性的访问。 说明 以下代码举例说明如何使用 Drive 对象访问驱动器的属性: Function ShowFreeSpac
FileSystemObject 对象 提供对计算机文件系统的访问。 说明 以下代码举例说明如何使用 FileSystemObject 对象返回一个 TextStream 对象,此对象可以被读
我是 javascript OOP 的新手,我认为这是一个相对基本的问题,但我无法通过搜索网络找到任何帮助。我是否遗漏了什么,或者我只是以错误的方式解决了这个问题? 这是我的示例代码: functio
我可以很容易地创造出很多不同的对象。例如像这样: var myObject = { myFunction: function () { return ""; } };
function Person(fname, lname) { this.fname = fname, this.lname = lname, this.getName = function()
任何人都可以向我解释为什么下面的代码给出 (object, Object) 吗? (console.log(dope) 给出了它应该的内容,但在 JSON.stringify 和 JSON.parse
我正在尝试完成散点图 exercise来自免费代码营。然而,我现在只自己学习了 d3 几个小时,在遵循 lynda.com 的教程后,我一直在尝试确定如何在工具提示中显示特定数据。 This code
我是一名优秀的程序员,十分优秀!