Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / February 2005

Tip: Looking for answers? Try searching our database.

read a Access table and processing record by record

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gmanassa - 16 Feb 2005 18:21 GMT
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.
Sean - 16 Feb 2005 21:09 GMT
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
gmanassa - 18 Feb 2005 16:09 GMT
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

> 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.
>
[quoted text clipped - 22 lines]
>    
> End Function
gmanassa - 18 Feb 2005 18:37 GMT
Sean,

Thanks, I got it to works

Thanks again.
George

> 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.
>
[quoted text clipped - 22 lines]
>    
> End Function
Tim Ferguson - 17 Feb 2005 17:40 GMT
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.