xris23
xris23

Reputation: 353

recordset close when updatesql?

I have an Excel VBA to update data in Access. I use the script below. I just have a small question. if I close the recordset with rs.close I get the message 'operation is not allowed when the object is closed'. If I do not use the rs.close then it works perfectly.

Upvotes: 1

Views: 378

Answers (1)

Erik A
Erik A

Reputation: 32642

  • Is the rs.close really necessary when using a sql?

    Nope. In fact, rs.close is rarely necessary at all. VBA will automatically remove objects when they go out of scope, which means that if they were defined in a sub, they get removed at the end of it. For ADODB, there were some bugs in an old version causing this to be unreliable, which means old code often contains rs.close or connection.close while they're not really necessary

  • I also tried to use cn.execute updatesql. How to set the recordlocking property?

    You can't. It doesn't really apply to action queries. The record locking options define if a record should be locked when starting to edit it, when updating it, or can't be locked at all because it's read-only, and since you're using an update query there's no time in between those

Upvotes: 1

Related Questions