If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Cycle Through Records in a Table using VBA
Hi all,
How can I cycle through all of the records in a table using VBA? Right now, I have VB code that looks at the first record when the form opens but I need to look at, and modify, all of the records in the table. Any help will be great!! |
#2
|
|||
|
|||
On Fri, 11 Feb 2005 10:11:26 -0700, RC- wrote:
Hi all, How can I cycle through all of the records in a table using VBA? Right now, I have VB code that looks at the first record when the form opens but I need to look at, and modify, all of the records in the table. Any help will be great!! You can adapt this. Add your own error handling. Public Sub EditTable() Dim Db As DAO.Database Dim rs As DAO.Recordset Set Db = CurrentDb Set rs = Db.OpenRecordset("YourTableName") rs.MoveFirst Do While Not rs.EOF rs.Edit If rs!LastName = "Jones" Then With rs rs![LastName] = "Johnston" .Update End With End If rs.MoveNext Loop rs.Close Db.Close Set rs = Nothing Set Db = Nothing End Sub -- Fred Please only reply to this newsgroup. I do not reply to personal email. |
#3
|
|||
|
|||
Perfect, that's what I was looking for!
Thanks much. RC- "fredg" wrote in message ... On Fri, 11 Feb 2005 10:11:26 -0700, RC- wrote: Hi all, How can I cycle through all of the records in a table using VBA? Right now, I have VB code that looks at the first record when the form opens but I need to look at, and modify, all of the records in the table. Any help will be great!! You can adapt this. Add your own error handling. Public Sub EditTable() Dim Db As DAO.Database Dim rs As DAO.Recordset Set Db = CurrentDb Set rs = Db.OpenRecordset("YourTableName") rs.MoveFirst Do While Not rs.EOF rs.Edit If rs!LastName = "Jones" Then With rs rs![LastName] = "Johnston" .Update End With End If rs.MoveNext Loop rs.Close Db.Close Set rs = Nothing Set Db = Nothing End Sub -- Fred Please only reply to this newsgroup. I do not reply to personal email. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Merging Records from one table to another on different databases | Mike Smith | General Discussion | 5 | November 3rd, 2004 07:02 PM |
Table Wizard Does Not Set Relationship if Foreign Key and Primary Key Name Do Not Match Exactly in Case. | HDW | Database Design | 3 | October 16th, 2004 03:42 AM |
New records can't be seen | rleblanc | Using Forms | 6 | August 14th, 2004 02:43 PM |
Table design | BillT | New Users | 11 | May 25th, 2004 03:41 PM |