Freedom Computers

ACCESS

VBA File handling - Make new or update existing Records


Dim dbase As DAO.Database
Dim recdset As DAO.Recordset

Set dbase = CurrentDb
Set reset = dbase.OpenRecordset("tablename")

*************************************************
'To add new records
reset.AddNew
recset![fieldname] = A$
recset.Update
*************************************************
'Or to update or edit existing records use
recset.movefirst
recset.Edit
recset![field name] = "whatever"
recset.Update
recset.MoveNext
************************************************************
'To do a global update

Dim dbase As DAO.Database
Dim recset As DAO.Recordset

Set dbase = CurrentDb
Set recset = dbase.OpenRecordset("Live Data")

recset.MoveFirst

Do Until rsRecordset.EOF
'This is just a counter to show progress
Text1.SetFocus
Text1.Text = c
c = c + 1

'Set the Variables
fname = rsRecordset![firstname]
init = Left(fname, 1)

recset.Edit ' prepare record for editing
recset![initial] = init 'Set field

recset.Update ' update record

recset.MoveNext
Loop
**************************************************