VB in the recordset prompt object closed when the operation is not allowed

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.