VB in the execution of queries, generally to determine whether it is empty, as long as the execution of the query executed select, can be used rs.eof or rs.recordcount to judge,
However, if you execute a logical judgment in the SQL that causes no SELECT statement to be executed, you will be judged by rs.eof or Rs.crcordcount, and the system prompts
The object cannot be manipulated when it is closed.
EG1:
@a int Set @a = 1 if @a = 0 Select @a
Note: If the script is executed and is judged with rs.eof, the object shutdown error is reported because no select query is executed and no content is returned.
EG2:
Select * into #itemno3 from Seorder a Inner Join on = B.finterid where = @fbillno -- ... Other processed select* from #itemno3
Note: The above paragraph if the script is executed, when judged with rs.eof, the system will also report the object shutdown error, because no select query started, no content returned.
Workaround:
1. The final result is written to the table in the stored procedure.
if exists(Select 1 fromsysobjectswhereXtype= 'U' andName= 'Itemno3') Drop TableItemno3Select * intoItemno3 fromSeorder aInner JoinSeorderentry b onA.finterid=B.finteridwhereFbillno= @fbillno--... Other treatment of--writes data to the result table, does not make queries in the stored procedure
View Code
2. After executing the stored procedure in VBA, execute the query result table separately
" exec rk_sp_huizong " & fitemid Set rs = execsql (sql) sql="select * FROM [ Result table]"set rs= execsql (SQL) " will not be prompted when the object is closed, no action is allowed If 0 Then End if
VB in the recordset prompt object closed when the operation is not allowed