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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through textboxes on form using variables 1

Status
Not open for further replies.

NvrSaDi

Programmer
Mar 11, 2003
45
US
In Access 2000, using VB, I can loop thru fields with sequential names in a table using variables, but having difficulty doing the same with textboxes on a form.

Example with table field names A1, A2...A20

dim n as integer
dim f1 as field
for n = 1 to 20
set f1 = rst.fields("A" & n)
f1 = some value
next n


Example with Textbox names A1, A2...A20

dim n as integer
dim ctl as Control

for n = 1 to 20
For Each ctl In frm.Controls
If ctl.ControlType = acTextBox Then
If ctl.Name = "A" & n Then (x being a variable from 1-20)
ctl.Value = some value
End If
Next ctl
next n

This is sort of a back door route to the results for looping thru the textboxes. Looking for a method similar to the table fields above.
 
Forms question (forum702)?

[tt]dim n as integer
dim f1 as control 'field
for n = 1 to 20
set f1 = frm.controls("A" & n) ' rst.fields("A" & n)
f1.value = <some value>
next n[/tt]

Or take a look at faq702-5010

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top