MoveNext not working for me...

frustrating

Registered User.
Local time
Today, 12:21
Joined
Oct 18, 2012
Messages
68
For some reason, this code doesn't seem to be working for me. I've never really had a problem with MoveNext until now.
What I'm trying to do is display all the applicable values form a query recordset into an email, but it's only displaying the last value.

Here is the function I made:
Code:
Public Function thepercent()
    Dim rsSQL As DAO.Recordset
    Dim DB As DAO.Database
    Set DB = CurrentDb
    Dim strsql As String
   strsql = "SELECT [Dept Root Source],[Expr1],[Error Description] FROM converttopercent1 WHERE [converttopercent1].[Dept Root Source] = '" & List20.Value & "'"
   Set rsSQL = DB.OpenRecordset(strsql)
   Do Until rsSQL.EOF
   thepercent = rsSQL!Expr1 & " due to " & [Error Description] & vbCrLf
   rsSQL.MoveNext
    Loop
    rsSQL.Close
    Set rsSQL = Nothing
    Set DBS = Nothing
End Function
Any idea on why it's not working?

I also had some code that displayed the recordcount, which was displaying the correct amount of records, so it isn't the table or query.
 
Last edited:
I don't think the problem is with MoveNext. You're getting the last value because you overwrite the value each pass through the loop. Sounds like you want:


thepercent = thepercent & rsSQL!Expr1 & " due to " & [Error Description] & vbCrLf
 
I don't think the problem is with MoveNext. You're getting the last value because you overwrite the value each pass through the loop. Sounds like you want:


thepercent = thepercent & rsSQL!Expr1 & " due to " & [Error Description] & vbCrLf

This fixed it! My only issue now is that the other fields aren't corresponding to anything other than the first field.

For example: Error Description repeats 4 times, while Expr1 changes.
 
Nevermind, I fixed it! I wasn't declaring the proper field.

Thank you very much. I never would've gotten this without your help!
 

Users who are viewing this thread

Back
Top Bottom