Edit a record on a Table

Accessme2

Registered User.
Local time
Today, 12:48
Joined
May 12, 2004
Messages
64
Hi everyone,

I was wondering if there is a way to do the following. I am writing a code where I am checking a condition if is true I want to be able to edit a table and change the value of couple of fields.
I am not very good in VB. So what I do is to move the calculated values into a text box fileds and hide them in the form and run an update query using those text boxes. But I am sure it got to be a better way.
 
You could use DAO to change the fields. You will need to set a reference to DAO 3.5/3.6 Object Library.

The below example I have used a checkbox as you condition = true and an If statement to change the fields.
Code:
If Me.CheckBox = True Then

Dim db As DAO.Database
Dim rst As DAO.Recordset


Set db = CurrentDb()
Set rst = db.OpenRecordset("Yourtablename", dbOpenDynaset)
With rst
        .Edit
        .Fields("Yourfieldname") =  Me.textboxname 
        .Fields("Anotherfieldname") = Me.textboxname
        .Update
        .Close
        
End With
Set rst = Nothing
Set db = Nothing

End If

NB. You might want to copy your tables before you begin. So that you can change your fields back to there original values if required.

Hope this Helps

Andy
 
Spacepro
Thanks for the help, I got it to work again thanks for all the help.
 

Users who are viewing this thread

Back
Top Bottom