Cann't update record value

D

Dou

My Code:

Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb

MySQL="Select * From WorkOrders WHERE [WONo] = '" & txtWONo & "*' ;'"

Set rs = db.OpenRecordset(MySQL, dbOpenDynaset)

CurrentDb.Execute "UPDATE rs SET [Status]='Close';"

but I cann't update the Status's value. why?

Thanks
 
K

Ken Snell [MVP]

You don't run update queries on recordsets; you edit them.

Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb

MySQL="Select * From WorkOrders WHERE [WONo] = '" & txtWONo & "*' ;'"

Set rs = db.OpenRecordset(MySQL, dbOpenDynaset)

rs.Edit
rs![Status].Value = "Close"
rs.Update

rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
 
J

John Spencer (MVP)

Although you can change your query to an update query and execute that.

Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb

MySQL="UPDATE WorkOrders SET Status = ""Close"" WHERE [WONo] = '" & txtWONo & "'"

CurrentDb.Execute mySQL

Ken Snell said:
You don't run update queries on recordsets; you edit them.

Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb

MySQL="Select * From WorkOrders WHERE [WONo] = '" & txtWONo & "*' ;'"

Set rs = db.OpenRecordset(MySQL, dbOpenDynaset)

rs.Edit
rs![Status].Value = "Close"
rs.Update

rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
--

Ken Snell
<MS ACCESS MVP>

Dou said:
My Code:

Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb

MySQL="Select * From WorkOrders WHERE [WONo] = '" & txtWONo & "*' ;'"

Set rs = db.OpenRecordset(MySQL, dbOpenDynaset)

CurrentDb.Execute "UPDATE rs SET [Status]='Close';"

but I cann't update the Status's value. why?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top