Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Updating DAO Record Moves it to the End of the Recordset

 
   Database Forums (Home) -> Visual Basic -> DAO RSS
Next:  Identity Range Problem  
Author Message
frodereck

External


Since: Jan 04, 2006
Posts: 2



(Msg. 1) Posted: Wed Feb 22, 2006 2:00 pm
Post subject: Updating DAO Record Moves it to the End of the Recordset
Archived from groups: microsoft>public>vb>database>dao (more info?)

I am trying to loop through a DAO recordset and replace characters as
needed. However, when the replacement consists of just appending a
character, the first record in the recordset seems to move to the end
of the recordset after the first iteration through the loop and has the
append done a second time. Here is the code (slightly modified to get
rid of the extra crud). This is legacy code so bare with me.

dim TempData as string, FindString as string, ReplaceString as string
FindString = "B.701"
ReplaceString = "B.7011"
Set DAORecord = m_SRDatabase.OpenRecordset( "SELECT MyField FROM
MyTable", dbOpenDynaset)
Do While Not DAORecord.EOF
TempData = DAORecord.Fields(0) & ""
TempString = Replace(TempData, FindString , ReplaceString )
If TempData <> TempString Then
DAORecord.Edit
DAORecord.Fields(0).Value = TempString
DAORecord.Update
End If
DAORecord.MoveNext
Loop

The preceding code will result in the first item in the recordset
having the string "B.70111" while all the others only have "B.7011".
I've traced through the code and this record is changed on the first
and then the last iterations of the loop.

I've gotten around this by replacing the Do While with this For/Next:

DAORecord.MoveLast
DAORecord.MoveFirst
For Count = 1 To DAORecord.RecordCount
.....same code inside
Next

So my fix does work, but I still want to know WHY it was happening in
the first place. Is this just a "feature" of DAO or was there some
error in the logic?

Thanks for your help.

 >> Stay informed about: Updating DAO Record Moves it to the End of the Recordset 
Back to top
Login to vote
Douglas J. Steele

External


Since: Mar 14, 2004
Posts: 716



(Msg. 2) Posted: Wed Feb 22, 2006 8:47 pm
Post subject: Re: Updating DAO Record Moves it to the End of the Recordset [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Nothing obviously wrong jumps out at me. However, it's almost always more
efficient to use a query, rather than VBA.

UPDATE MyTable
SET MyField = Replace([MyField], "B.701", "B.7011")
WHERE MyField LIKE "*B.701*"

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"frodereck" wrote in message

>I am trying to loop through a DAO recordset and replace characters as
> needed. However, when the replacement consists of just appending a
> character, the first record in the recordset seems to move to the end
> of the recordset after the first iteration through the loop and has the
> append done a second time. Here is the code (slightly modified to get
> rid of the extra crud). This is legacy code so bare with me.
>
> dim TempData as string, FindString as string, ReplaceString as string
> FindString = "B.701"
> ReplaceString = "B.7011"
> Set DAORecord = m_SRDatabase.OpenRecordset( "SELECT MyField FROM
> MyTable", dbOpenDynaset)
> Do While Not DAORecord.EOF
> TempData = DAORecord.Fields(0) & ""
> TempString = Replace(TempData, FindString , ReplaceString )
> If TempData <> TempString Then
> DAORecord.Edit
> DAORecord.Fields(0).Value = TempString
> DAORecord.Update
> End If
> DAORecord.MoveNext
> Loop
>
> The preceding code will result in the first item in the recordset
> having the string "B.70111" while all the others only have "B.7011".
> I've traced through the code and this record is changed on the first
> and then the last iterations of the loop.
>
> I've gotten around this by replacing the Do While with this For/Next:
>
> DAORecord.MoveLast
> DAORecord.MoveFirst
> For Count = 1 To DAORecord.RecordCount
> .....same code inside
> Next
>
> So my fix does work, but I still want to know WHY it was happening in
> the first place. Is this just a "feature" of DAO or was there some
> error in the logic?
>
> Thanks for your help.
>

 >> Stay informed about: Updating DAO Record Moves it to the End of the Recordset 
Back to top
Login to vote
frodereck

External


Since: Jan 04, 2006
Posts: 2



(Msg. 3) Posted: Mon Feb 27, 2006 10:43 am
Post subject: Re: Updating DAO Record Moves it to the End of the Recordset [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks for the reply Doug. Unfortunately my VB code throws an error on
Replace in a DAO Update statement
 >> Stay informed about: Updating DAO Record Moves it to the End of the Recordset 
Back to top
Login to vote
Douglas J. Steele

External


Since: Mar 14, 2004
Posts: 716



(Msg. 4) Posted: Mon Feb 27, 2006 5:55 pm
Post subject: Re: Updating DAO Record Moves it to the End of the Recordset [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Ah, yes. Sorry, I forgot you're running from VB, not from within Access.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"frodereck" wrote in message

> Thanks for the reply Doug. Unfortunately my VB code throws an error on
> Replace in a DAO Update statement
>
 >> Stay informed about: Updating DAO Record Moves it to the End of the Recordset 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Add new record in DAO recordset locks entire table (using .. - I'm having problem with using DAO recordset in MS Access 2000 to append record into a table. Following is the code: Dim wkSpace As Workspace, db As Database Dim rstTrans As DAO.Recordset Set wkSpace = DBEngine.Workspaces(0) Set db =..

dao recordset error trapping - I have a dao recordset which I update with the following code: With rsOrderShip .Edit !CustCode = frmOrders.txtSTCustCode.Text !stcustname = frmOrders.txtSTCustName.Text !staddress1 = frmOrders.txtSTAddress1.Text ....

Error 3167 recordset is delete - Hello, ich habe in verschiedenen Newsgroups gesucht aber keine Lösung zu dem folgenden Problem gefunden. Zwei Personen arbeiten gemeinsam mit einem VB6-Programm an einer ACCESS 2000 Datenbank Der Zugriff von VB auf ACCESS erfolgt mit DAO 3.60. Eine de...

Problem updating dataset - I have a form with three data grids on it; each of which is bound to a dataset. These grids are all related such that the first is the parent to the second and the second is a parent to the third. During runtime if the user makes changes or additions....

Deleting records from DAO recordset - [posted earlier in other group] Hi All, I'm using the following code to delete one or more records from a DAO recordset. The code is working but I was wondering if I need to Update the recordset with: rsDel.Update? Public Function DelRecs(Lstview As....
   Database Forums (Home) -> Visual Basic -> DAO All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]