By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

deleting a row value

P: 553
If i want to delete a record from a table , i use the following code:

Expand|Select|Wrap|Line Numbers
  1. Dim rst As DAO.Recordset
  2. Dim db As DAO.Database
  4. Set db = CurrentDb
  6. Set rst = db.OpenRecordset("Select name FROM Table1 WHERE name='" & "name1" & "'")
  8. rst.Edit
  9. rst.Fields("name") = "name2"
  10. rst.Delete
It works. My question is how can i delete a particular field value of a record?

For example: Table1 contains
Name Age
Name1 10
Name2 20 --- If i want to delete only 20 not the whole row , how can
it be done ?

2) Also, when i open a RecordSet for delete or update purposes only, why still do i have to write a SELECT statement like above ? Are there any other simple methods out there?
Jul 25 '07 #1
Share this Question
Share on Google+
3 Replies

Expert 2.5K+
P: 3,532
You have posted your question in the Articles section rather than the Forum section.

I have moved it across for you.

Jul 25 '07 #2

Expert 100+
P: 1,206
I think you want an update query rather than a delete query.

Expand|Select|Wrap|Line Numbers
  1. UPDATE tblPerson SET age = Null
  2. WHERE name = 'Jared'
You don't need an open recordset to do this either. You can simply use the Docmd.RunSQL command.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_Click()
  3. Dim strSQL As String
  5. strSQL = "UPDATE tblPerson SET age = Null WHERE name = 'Jared'"
  7. Docmd.RunSQL strSQL
  8. End Sub
There are many other ways to manipulate recordsets and you can open tables directly or even open saved queries. I suggest taking a look at the available methods of a recordset and the examples for them provided in the help files.
Jul 25 '07 #3

Expert 2.5K+
P: 3,072
Or even shorter:
Expand|Select|Wrap|Line Numbers
  1. currentdb.execute ("UPDATE tblPerson SET age = Null WHERE name = 'Jared'")
Jul 27 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.