Loop stuck at the first record when execution of module ends...

dkc123

Registered User.
Local time
Yesterday, 19:28
Joined
Mar 21, 2012
Messages
17
Hi friends,

Got stuck with the first loop not moving ahead...The function is executing fine ..but oce it returns to the originat recordset loop startsat the first record again...
plz help??
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strtoid As String, strtnid As String
'strtoid = Me.txttoid
'strtnid = Form_TestSelectionUnboundB.TestName
Set db = CurrentDb
struser = GetUserName()
strreg = Me.RegistrationID

Set rstoid = db.OpenRecordset("SELECT BkOrdrTblID, BkDate, BkRegistrationID, BkPOG, BkDscnt,BkAmount,BkUser, BkRemarks, BkDept FROM BkOrdrTbl")

rstoid.AddNew
rstoid("BkRegistrationID").Value = strreg
rstoid("BkDate").Value = Now()
rstoid("BkPOG").Value = Me.cboPOG
rstoid("BkDscnt").Value = Nz(Me.txtDiscount, 0)
'TEMP=>>rstoid("BkUser").Value = Nz(struser, 0)
rstoid("BkRemarks").Value = Me.txtbkremarks
rstoid("BkDept").Value = Me.txtprefixid
'rstoid("BkAmnt").Value = Me.txtAmount


rstoid.Update
rstoid.Requery
rstoid.FindLast "BkRegistrationID=" & strreg & ""
strtoid = rstoid!BkOrdrTblID
rstoid.Close
'sqlnpt = ("SELECT BkOrdrTblID, TestName, TestCost, BookedTest FROM NonProfileTests")
'sqltmptbl = ("SELECT * FROM TmpTestSelectortbl")
strtid = strtoid

'----------?--------



Set rs = db.OpenRecordset("TmpTestSelectortbl")

With rs
Do Until rs.EOF
rs.MoveFirst
      DoCmd.SetWarnings (WarningsOff)
            DoCmd.RunSQL ("Insert into NonProfileTests (TestOrderID, TestName, TestCost, BookedTest) values (" & strtoid & ", ' " & rs("TestName") & " ','" & rs("TestCost") & "', -1   )")
          
            strtnid = rs!TestName

Call SaveTestPro(strtnid, strtoid)
 
 rs.MoveNext
 Loop
 End With
 DoCmd.SetWarnings (WarningsOn)
 
The rs.MoveFirst is inside your Do Until loop. Always put the .MoveFirst outside the loop.

Code:
Set rs = db.OpenRecordset("TmpTestSelectortbl")

With rs
[COLOR="SeaGreen"]rs.MoveFirst [/COLOR]   <------------+
Do Until rs.EOF              |
[COLOR="Red"]rs.MoveFirst[/COLOR]    -------------+
      DoCmd.SetWarnings (WarningsOff)
            DoCmd.RunSQL ("Insert into NonProfileTests (TestOrderID, TestName, TestCost, BookedTest) values (" & strtoid & ", ' " & rs("TestName") & " ','" & rs("TestCost") & "', -1   )")
 
Last edited:
Thanks The_Doc_Man...
 

Users who are viewing this thread

Back
Top Bottom