Form record loop not picking up textboxs

pekajo

Registered User.
Local time
Tomorrow, 08:46
Joined
Jul 25, 2011
Messages
135
Hi,
I have I think a strange loop problem.
I have a loop that runs though the records on my form and is working correctly for any data fields but it will only pickup the first textbox field and not change for the following records.
For example if I display (msgbox) the first record with the textbox and record ID I get:

Jones 1
Next record would be
Jones 2
and so on.

Any help would be appreciated.
Peter
 
Hi Peter. Not sure I follow what you just said. Can you post your code? Thanks!
 
Hi,
Thanks for the reply.
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.MoveLast
rs.MoveFirst
Dim idx As Integer
For idx = 1 To rs.RecordCount
aa = Me!Text6 ' textbox
a1 = rs!ID ' record ID
MsgBox aa & " " & a1
rs.MoveNext
nn = nn + 1
Next idx
Set rs = Nothing
With DoCmd
.Save
.Close
End With
End Sub
 
Hi,
Thanks for the reply.
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.MoveLast
rs.MoveFirst
Dim idx As Integer
For idx = 1 To rs.RecordCount
aa = Me!Text6 ' textbox
a1 = rs!ID ' record ID
MsgBox aa & " " & a1
rs.MoveNext
nn = nn + 1
Next idx
Set rs = Nothing
With DoCmd
.Save
.Close
End With
End Sub
Hi. You have two options (I think):
1. Use Recordset, instead of RecordsetClone, or
2. Use !FieldName, instead of Me!Text6
Hope it helps...
 
Hi,
Recordset worked like a charm. Thanks a lot.
If possible can you tell me the difference between the two if it's not to much trouble.
Thanks again
Peter
 
Hi,
Recordset worked like a charm. Thanks a lot.
If possible can you tell me the difference between the two if it's not to much trouble.
Thanks again
Peter

Hi Peter. Glad to hear you got it to work. The clone is just a copy of the form’s records. So, you were mixing the two by using both !ID and Me.Text6. When you switch to the regular recordset, you’re not mixing two things anymore.
 
as an aside, I noticed you didn't dim aa, a1, or nn. Or at least you didn't include it in the code you posted.

Did you declare option explicit in the declarations? does your code compile?
 

Users who are viewing this thread

Back
Top Bottom