By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

Looping through a subform records

P: 44
Good evening all i am trying to loop through a subform records and i need it to display the selected value from each of the records eg:
record 1 prod# 2
record 2 prod# 5
record 3 prod# 3

so in the above senario it would loop 3 times and each time output 2 then 5 then 3. Currently my code will loop through 3 times but constantly output just the first value(2) attached is the code any help would be much appriceated
Expand|Select|Wrap|Line Numbers
  1. Set rs = Me.[sqlOrderDetails subform].Form.RecordsetClone
  2.  
  3. Do While Not rs.EOF
  4.  
  5. prod# = Me.Form![sqlOrderDetails subform]!ProdID
  6. Debug.Print prod#
  7.  
  8. rs.MoveNext
  9.  
  10. Loop
  11.  
  12. Set rs = Nothing
Aug 21 '12 #1

✓ answered by TheSmileyCoder

As rabbit has allready explained, line 5 of your code you are reference the values stored in the form, instead of the recordsetCLONE.
Expand|Select|Wrap|Line Numbers
  1. prod# = rs!ProdID
should work, assuming ProdID is the name of the FIELD in the underlying recordset.

Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,366
That's because you're setting your variable to the value on the form. Not the value in the recordset.
Aug 21 '12 #2

TheSmileyCoder
Expert Mod 100+
P: 2,321
As rabbit has allready explained, line 5 of your code you are reference the values stored in the form, instead of the recordsetCLONE.
Expand|Select|Wrap|Line Numbers
  1. prod# = rs!ProdID
should work, assuming ProdID is the name of the FIELD in the underlying recordset.
Aug 21 '12 #3

P: 44
Thanks for your help Rabbit and TheSmileyCoder
Aug 22 '12 #4

TheSmileyCoder
Expert Mod 100+
P: 2,321
Your welcome. Glad to be of service.
Aug 22 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.