Editing multiple records

wtrimble

Registered User.
Local time
Today, 13:37
Joined
Nov 13, 2009
Messages
177
Hello,

I'm tryin to add the value "2007" to a field (YearUpdated) in a table (tblgdmreport) for all records. (I created a button to carry out the event)

I have the following but I know I'm missing something/not doing it correctly.

Code:
Private Sub Command9_Click()
Dim dbmydb As Database
Set dbmydb = OpenDatabase("P:\Databases\Access Database Development\1. Current Database\NEW\databaseNEW")
Dim rsmyrs As Recordset
Set rsmyrs = dbmydb.OpenRecordset("tblgdmreport", dbOpenDynaset)
If Not rsmyrs.EOF Then rsmyrs.MoveFirst
Do While Not rsmyrs.EOF
rsmyrs.Edit
rsmyrs.Fields("yearupdated").Value = "2007"
rsmyrs.MoveNext
Loop
 
End Sub

Any help would be greatly appreciated!
 
Just create an update query instead and run it. It is much more efficient.
 
Ah yes, that's the way to do it.

For future reference though, what should the coding be like?
 
I would just create an Update query in the query designer and then save it. You can then execute it with:

CurrentDb.Execute "YourQueryNameHere", dbFailOnError
 
I was talking about my original coding method, but anyways, thanks.
 

Users who are viewing this thread

Back
Top Bottom