| re: Using a VB function to update records
Hi Sid,
You may be able to use an update query to do what you try to do, but I
don't know that much about those. What I would do is work with a
recordset, from code.
In order to open a recordset you must first include a reference to
Microsoft DAO Object Library (in the VB editor click Tools, then
References, browse down to Microsoft DAO 3.6 Object Library, and check
it). Then you declare the Recordset by writing the following line of
code:
Dim rs As DAO.Recordset
"rs" is the name of the recordset, you may, and should, change it.
Next you build the rs by writing the following:
Set rs = CurrentDB.OpenRecordset("<Your Select Query goes here>")
Then you have several commands you can use on the recordset:
rs.MoveFirst - Moves to the first record in the recordset.
rs.MoveNext - Obviously, moves to the next...
rs.MoveLast - too obvious...
rs.Edit - Opens the current record for editing.
rs.Update - Saves changes you made to the table. You must use this
method
before moving to the next record or changes are lost.
to access fields in your table just use:
rs!<name_of_your_field>
They'll behave almost like a variable, which is most conveniant.
Hope this helps...
Noam Nelke, Israel. |