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

deleting a row value

100+
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
  3.  
  4. Set db = CurrentDb
  5.  
  6. Set rst = db.OpenRecordset("Select name FROM Table1 WHERE name='" & "name1" & "'")
  7.  
  8. rst.Edit
  9. rst.Fields("name") = "name2"
  10. rst.Delete
  11.  
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


missinglinq
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.

Linq
Jul 25 '07 #2

JKing
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'
  3.  
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()
  2.  
  3. Dim strSQL As String
  4.  
  5. strSQL = "UPDATE tblPerson SET age = Null WHERE name = 'Jared'"
  6.  
  7. Docmd.RunSQL strSQL
  8. End Sub
  9.  
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

nico5038
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'")
  2.  
Nic;o)
Jul 27 '07 #4

Post your reply

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