Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping/collections of Textboxes on Forms

Status
Not open for further replies.

ghalewood

Programmer
Nov 13, 2001
42
0
0
EU
I have a form that has many, many text boxes on it. I intend to populate these text boxes using code. I have a target petrol station and want to show data for the nearest 22 other stations around it. I already have the data in other tables, but rather than have to code

form!address_1 = rsaddress!address
form!diesel_1 = rsprices5!diesel_price
form!price_diff_1 = rsprices5!price_diff
rsaddress.readnext
form!address_2 = rsaddress!address
form!diesel_2 = rsaddress!diesel
form!price_diff_2 = rsprices5!price_diff
rsaddress.readnext
etc etc

bearing in mind that I have over 150 fields to populate in this way, as well as many other fields to be calculated, I would like to group the fields and reference them by subscript
do while etc
form!address(intSub) = rsaddress!address
form!diesel(intSub) = rsaddress!diesel
intSub = intSub + 1
rsaddress.readnext
loop

I cannot see where I can tell Access that I intend to reference the text boxes in that way.

Can anyone help

Thanks
Graham
 
One way you can refer to controls would be to use the controls property of the form - so for example:
Code:
Do While rsaddress.eof
   Me.Controls("address" & intSub).Value = rsaddress!address
   Me.Controls("diesel" & intSub).Value = rsaddress!diesel
   intSub = intSub + 1
   rsaddress.readnext
Loop

This would of course assume that your code was in the class module for the form.

You could also do this:
Code:
For inSub = 1 to rsaddress.RecordCount
   Me.Controls("address" & intSub).Value = rsaddress!address
   Me.Controls("diesel" & intSub).Value = rsaddress!diesel
   intSub = intSub + 1
   rsaddress.readnext
Next
But it works out to be the same anyway - I doubt there would be much difference in performance...

Hope this helps!

Mincefish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top