Looping Question (1 Viewer)

Jalnac74

Registered User.
Local time
Yesterday, 17:00
Joined
Apr 4, 2015
Messages
23
Hi all,

I have a form with a subform. On the subform I change the details in one field in a record and then want vba to change that field in other records where certain other criteria are the same (from other fields). I have managed all of this but then the loop doesn't stop. I have looked everywhere I usually look for a solution but have had no luck, any help would be appreciated.

Here is the code I have:
Code:
Sqlstr2 = "[class]='" & Me.Class & "'"
   
   Set rst = Me.Recordset
               
    If rst.NoMatch Then
        MsgBox "Record not found."
        
    Else
        Do While Not rst.EOF
                rst.FindNext Sqlstr2
                rst.Edit
                [LSA] = TempVars!VarTA 'tempvars is set earlier in the code block to me.LSA - this works!
                rst.Update
                               
            Loop
       
    End If
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:00
Joined
Aug 30, 2003
Messages
36,123
The loop needs this before Loop:

rst.MoveNext

Also, this doesn't refer to the recordset:

[LSA] =...
 

Cronk

Registered User.
Local time
Today, 10:00
Joined
Jul 4, 2013
Messages
2,771
You are not moving off the first record. Add another line.
Code:
While Not rst.EOF
     rst.FindNext Sqlst
      rst.Edit
      [LSA] = TempVars!VarTA 'tempvars is set earlier in the code block to me.LSA - this works!
      rst.Update
      [B][COLOR=Red]rst.findnext sqlst[/COLOR][/B]             
 Loop

I'd do it like this

Code:
rst.FindNext Sqlst
do while not rst.nomatch
    rst.edit
     ....
    rst.update
    rst.FindNext Sqlst
loop
 

Jalnac74

Registered User.
Local time
Yesterday, 17:00
Joined
Apr 4, 2015
Messages
23
Thanks Cronk, this is now working as I wanted it to.
 

Users who are viewing this thread

Top Bottom