read a Access table and processing record by record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone please provide a sample of how to read a Access table.
I need to set one field based of the value of other fields.
I would like to do this thru VBasic. Because I am going to have multiple
test conditions.
 
Usign ADO, this is how you'd do such a thing. I've experienced a few very obscure problems using DAO (usually on multiuser/networked databases) which ADO doesn't seem to have a problem with.

Function UpdateTable()

Dim rsWork As ADODB.Recordset
Dim strSQL As String

strSQL = "SELECT * FROM tMyTable;"
Set rsWork = New ADODB.Recordset
rsWork.Open strSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
If rsWork.BOF = False Or rsWork.EOF = False Then
rsWork.MoveFirst
Do While rsWork.EOF = False
If rsWork("ThisField") > rsWork("ThatField") Then
rsWork("SomeOtherField") = "This record changed"
rsWork.Update
End If
rsWork.MoveNext
Loop
Else
MsgBox ("This recordset is empty")
End If
rsWork.Close
Set rsWork = Nothing

End Function
 
I need to set one field based of the value of other fields.

This is nearly always a Bad Thing To Do -- if a value depends only on other
fields, then it should not be in the table at all, but in the query.

Try reading about Second Normal Form.

HTH


Tim F
 
Sean,

I click On module and added your code here. I make the changes relating to
my table. I wrote the SQL statement to create the table.

How do I get this Module to execute against the table

Thanks
George
 
Back
Top