Visual Basic DAO code

Hi,
As I have not used VB for a very long time, thus my request here.  Can someone please write the VB code to do the following which I intend to put it in a Form :
1. Retrieve a table
2. Go to the beginning of the record, and then start looping one record at a time until EOF is reached.
3. retrieve the contents of the field "ID" and pass it to a variable.
4. [ here I will write the code what to do with the variable ]
5. Then assign the value of that variable to another field called "CheckDigit". this field is within the same Table.
6. Loop to the next record -- until the end of the records is reached.

Thanks.
Jothy

jegajothyretiredAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vb_jonasCommented:
Are you sure you would like to use DAO? ADO.NET is much more up to date.

If DAO:
http://www.dotnet247.com/247reference/msgs/18/90914.aspx

If ADO.NET:
0
jegajothyretiredAuthor Commented:
I am lost after the line Move First
Could you please write me the code to assign a variable to a field called ID in the Table.
Also why the
 For x = 0 to 5 -- hope this is the right syntax as I am typing from memory.
thanks.
Jothy
0
GrahamSkanRetiredCommented:
Option Explicit

Private Sub Command1_Click()
Dim db As Database
Dim rs As Recordset
    Set db = OpenDatabase("C:\Documents and Settings\user name\My Documents\Generaltest.mdb")
        Set rs = db.OpenRecordset("MyTable")
            rs.MoveFirst
            Do Until rs.EOF
                Myvariable = rs.Fields("ID")
                'your code
                rs.MoveNext
            Loop
        rs.Close
    db.Close
End Sub
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

jegajothyretiredAuthor Commented:
Graham,
The syntax : Myvariable = rs.Fields("ID")
If I understand it correctly, it assigns from right to left, is this correct. i.e. the contents of the field ID is transferred to Myvariable.
I want a rs.Fields("ID") = myvariable.  That is the contents of myvariable to go into the field "ID".
Is this the correct syntax.
Thanks.
Jothy
0
GrahamSkanRetiredCommented:
You are right. Silly mistake. It reveals that I didn't actually test the code.

0
vb_jonasCommented:
You will need to do this to edit

rs.Edit
rs.Fields("ID")=myvariable
rs.Update

0
GrahamSkanRetiredCommented:
Careful reading of your requirement, third thoughts and a prompt from vb_jonas:

Private Sub Command1_Click()
Dim db As Database
Dim rs As Recordset
    Set db = OpenDatabase("C:\Documents and Settings\user name\My Documents\Generaltest.mdb")
        Set rs = db.OpenRecordset("MyTable")
            rs.MoveFirst
            Do Until rs.EOF
                Myvariable = rs.Fields("ID")
               
                'your code
                rs.Edit
                rs.Fields("CheckDigit") = MyVariable
                rs.Update
                rs.MoveNex
            Loop
        rs.Close
    db.Close
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jegajothyretiredAuthor Commented:
Bravo for an assignment well done.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.