Change string to control?

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

I have aand .ADP function to shich I am passing it a lot of field to
manuipulate.

When the program loads a certain form, it needs to update the caption of
each of the control buttons. Rather thatn listing all fo teh control
separately, I wanted to be able to hav the program cycle through the
controls. For example:

There are 16 buttons, all with a name starting with "OptionA". (e.g
OptionA1, OptionA2, OptionA3, etc.)
There are 16 buttons, all with a name starting with "OptionB".
There are 16 buttons, all with a name starting with "OptionC".
There are 16 buttons, all with a name starting with "OptionD".
There are 16 buttons, all with a name starting with "OptionE".

I want to pass the system a recordset and a parameter. The recordset
contains 16 captions. Parameter is "OptionA". The system will then go
through the form and update all controls that start with "OptionA"

Effectvely, I am trying to write a simple code similar to the following (but
this code doesn't work):

[recordset code works up to this point]
["Prefix" has been passed through to this function as "OptionA"]

function UpdateFormControls (rs as recordset, Prefix as string)
counter = 0
Set conn = ADO_Connect
do while not rs.EOF
counter = counter + 1
Prefix & [counter].caption = rs!ItemName
wend
end function

Effectvely, I am trying to change "Prefix & [counter]" into a control.

Does anyone haev any idea how to do this?

Thanks, Stephen
 
Stephen said:
I have aand .ADP function to shich I am passing it a lot of field to
manuipulate.

When the program loads a certain form, it needs to update the caption
of each of the control buttons. Rather thatn listing all fo teh
control separately, I wanted to be able to hav the program cycle
through the controls. For example:

There are 16 buttons, all with a name starting with "OptionA". (e.g
OptionA1, OptionA2, OptionA3, etc.)
There are 16 buttons, all with a name starting with "OptionB".
There are 16 buttons, all with a name starting with "OptionC".
There are 16 buttons, all with a name starting with "OptionD".
There are 16 buttons, all with a name starting with "OptionE".

I want to pass the system a recordset and a parameter. The recordset
contains 16 captions. Parameter is "OptionA". The system will then
go through the form and update all controls that start with "OptionA"

Effectvely, I am trying to write a simple code similar to the
following (but this code doesn't work):

[recordset code works up to this point]
["Prefix" has been passed through to this function as "OptionA"]

function UpdateFormControls (rs as recordset, Prefix as string)
counter = 0
Set conn = ADO_Connect
do while not rs.EOF
counter = counter + 1
Prefix & [counter].caption = rs!ItemName
wend
end function

Effectvely, I am trying to change "Prefix & [counter]" into a control.

Does anyone haev any idea how to do this?

Thanks, Stephen

Something like this:

'----- start of revised air code -----
Function UpdateFormControls (rs as recordset, Prefix as string)

counter = 0

With rs
.MoveFirst
Do Until rs.EOF
counter = counter + 1
Me.Controls(Prefix & counter).Caption = !ItemName
.MoveNext
Loop
End With

End Function
'----- end of code -----

I've left out any error-handling and logic to make sure you don't have
more records in rs than you have controls.
 
Back
Top