A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Updating all records in a recordset



 
 
Thread Tools Display Modes
  #1  
Old May 11th, 2004, 10:55 PM
BrianC
external usenet poster
 
Posts: n/a
Default Updating all records in a recordset

The following code returns multiple records to the
recordset. How do I update each record in the recordset
with the value of lngNext?

Set MyDb = CurrentDb
Set qdf = MyDb.QueryDefs("QueryBlockAv")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenDynaset)
rs.Edit
rs![Booking ID] = lngNext
rs.Update
rs.Close
Set rs = Nothing

This I believe only updates the first record. Is there a
way of looping through each record in the set and also
when do I know that I've got to the end?
  #2  
Old May 11th, 2004, 11:40 PM
Chris Nebinger
external usenet poster
 
Posts: n/a
Default Updating all records in a recordset

My Code below:

Chris Nebinger


-----Original Message-----
The following code returns multiple records to the
recordset. How do I update each record in the recordset
with the value of lngNext?

Set MyDb = CurrentDb
Set qdf = MyDb.QueryDefs("QueryBlockAv")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenDynaset)

'*****************
Do Until rs.EOF
'*****************

rs.Edit
rs![Booking ID] = lngNext
rs.Update

'*****************
rs.movenext
loop
'*****************

rs.Close
Set rs = Nothing

This I believe only updates the first record. Is there a
way of looping through each record in the set and also
when do I know that I've got to the end?
.

  #3  
Old May 11th, 2004, 11:49 PM
lbrinkman
external usenet poster
 
Posts: n/a
Default Updating all records in a recordset

You see check out the Access HELP files. Your "Next prm" needs to be
inserted after rs.Update. Otherwise, you are not looping through the
records. Also, you might want to close the database: Set Mydb = Nothing

For Each element In group
[statements]
[Exit For]
[statements]
Next [element]
---Phil Szlyk

"BrianC" wrote in message
...
The following code returns multiple records to the
recordset. How do I update each record in the recordset
with the value of lngNext?

Set MyDb = CurrentDb
Set qdf = MyDb.QueryDefs("QueryBlockAv")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenDynaset)
rs.Edit
rs![Booking ID] = lngNext
rs.Update
rs.Close
Set rs = Nothing

This I believe only updates the first record. Is there a
way of looping through each record in the set and also
when do I know that I've got to the end?



  #4  
Old May 12th, 2004, 12:34 AM
Marc
external usenet poster
 
Posts: n/a
Default Updating all records in a recordset

Answers inline
The following code returns multiple records to the
recordset. How do I update each record in the recordset
with the value of lngNext?

Set MyDb = CurrentDb
Set qdf = MyDb.QueryDefs("QueryBlockAv")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenDynaset)

if rs.RecordCount = 0 then
' no records processing
goto eventExit
end if

while rs.EOF = false
rs.Edit == never actually used this command, not really necessary
rs![Booking ID] = lngNext
rs.Update

rs.MoveNext
wend
rs.Close
Set rs = Nothing

This I believe only updates the first record. Is there a
way of looping through each record in the set and also
when do I know that I've got to the end?


HTH
Marc


  #5  
Old May 12th, 2004, 02:57 AM
VanT.Dinh
external usenet poster
 
Posts: n/a
Default Updating all records in a recordset

OTOH, if you update a large number of Records, it is more
efficient to use:

[CurrentDatabaseObject].Execute [Update Query/SQL String]

rather than traversing the Recordset one Record/Rw at a
time.

HTH
Van T. Dinh
MVP (Access)



-----Original Message-----
The following code returns multiple records to the
recordset. How do I update each record in the recordset
with the value of lngNext?

Set MyDb = CurrentDb
Set qdf = MyDb.QueryDefs("QueryBlockAv")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenDynaset)
rs.Edit
rs![Booking ID] = lngNext
rs.Update
rs.Close
Set rs = Nothing

This I believe only updates the first record. Is there a
way of looping through each record in the set and also
when do I know that I've got to the end?
.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:37 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.