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

Form load event simple loop required

Status
Not open for further replies.

pdeman

Programmer
Feb 17, 2010
39
GB
Hello

I have the following code:

Private Sub Form_Load()
Dim lngBool As Boolean

lngBool = fCmdButTextPic(Me.CmdColorButton1, 12058623)
lngBool = fCmdButTextPic(Me.CmdColorButton2, 12058623)
lngBool = fCmdButTextPic(Me.CmdColorButton3, 12058623)
lngBool = fCmdButTextPic(Me.CmdColorButton4, 12058623)
lngBool = fCmdButTextPic(Me.CmdColorButton5, 12058623)
lngBool = fCmdButTextPic(Me.CmdColorButton6, 12058623)
lngBool = fCmdButTextPic(Me.CmdColorButton7, 12058623)
lngBool = fCmdButTextPic(Me.CmdColorButton8, 12058623)

End Sub

The real code has many more likewise lines as the buttons are 1 to 100.

Can someone help by changing code to a simple loop so I don’t have to write the lines 100 times?

Thank you
 
for i = 1 to 100
lngBool = fCmdButTextPic(Me.controls("CmdColorButton" & i), 12058623)
next i

But not sure what you are doing returning the lngbool. The value is the value of the last control.

you can also put something in the tag property like a :
?

dim ctl as access.control
for each ctl in me.controls
if ctl.tag = "?" then
lngBool = fCmdButTextPic(ctl, 12058623)
end if
next ctl
 
Hello MajP

Excellent both work.
I agree with your advice about the tag prperty will go with this.
Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top