Assign value to textbox objects in a subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear,
I have a mainform and a subform. The subform contains, say 100 textboxes.
I have been unsuccessful trying to assign value to textboxes programmically.
What I am trying to do is that I delibrately name those 100 textboxes in
numberic order, 1-100 in each Name property.
I am hoping this way, I do not have to type 100 textboxes names to assign
the value I retrieved from the database.
Any idea?
I have one hardcoded assignment statment that I was able to use for your
reference:
Forms!frmMainform!frmSub.Form.[3] = "3"
I just wasn't able to replace the [3] using a variable name instead of the
name of the object.
Thank you for your assistance.
Martin
 
Sample I saw about this has line of
code that looks like Me.Controls("txtMth" & i).
Since you are using a subform the Me part
may be different depending where you put the
code and I guess you just need Me.Controls(i).
 
Thanks Alicia for responding to my question. I still have a little bit
problem making it work. I will cointinue to work at my end and hope there
are others who may have different approach.

What I am doing now is exploring the following loop :

For Each ctl In frmSub
msgbox ctl.Name
Next ctl

The loop gave me a list of control names in the order of creation, I
believe. I just hope I could manipulate the order by refering their names
(1-100) of those objects in a loop. For example I named the first textbox
object as 1, and the second one is 2. under their name property. The
following is my expected logic statement but not working:

For i =1 to 100
Forms!frmMainform!frmSub.Form.=GlobalArrayRecord(i)
next i


Thank you!
Martin

Alicia said:
Sample I saw about this has line of
code that looks like Me.Controls("txtMth" & i).
Since you are using a subform the Me part
may be different depending where you put the
code and I guess you just need Me.Controls(i).

Martin said:
Dear,
I have a mainform and a subform. The subform contains, say 100 textboxes.
I have been unsuccessful trying to assign value to textboxes programmically.
What I am trying to do is that I delibrately name those 100 textboxes in
numberic order, 1-100 in each Name property.
I am hoping this way, I do not have to type 100 textboxes names to assign
the value I retrieved from the database.
Any idea?
I have one hardcoded assignment statment that I was able to use for your
reference:
Forms!frmMainform!frmSub.Form.[3] = "3"
I just wasn't able to replace the [3] using a variable name instead of the
name of the object.
Thank you for your assistance.
Martin
 
Martin said:
Thanks Alicia for responding to my question. I still have a little
bit
problem making it work. I will cointinue to work at my end and hope
there
are others who may have different approach.

What I am doing now is exploring the following loop :

For Each ctl In frmSub
msgbox ctl.Name
Next ctl

The loop gave me a list of control names in the order of creation, I
believe. I just hope I could manipulate the order by refering their
names (1-100) of those objects in a loop. For example I named the
first textbox object as 1, and the second one is 2. under their name
property. The
following is my expected logic statement but not working:

For i =1 to 100
Forms!frmMainform!frmSub.Form.=GlobalArrayRecord(i)
next i


Try this:

Dim i As Integer

With frm = Forms!frmMainform!frmSub.Form
For i = 1 to 100
.Controls("" & i) = GloballArrayRecord(i)
Next i
End With

The concatenation of "" with i converts i to a string value, which is
then used as a string index into the form's Control collection.
 
Dirk,
It works beatifully. Thanks a lot.
Martin

Dirk Goldgar said:
Martin said:
Thanks Alicia for responding to my question. I still have a little
bit
problem making it work. I will cointinue to work at my end and hope
there
are others who may have different approach.

What I am doing now is exploring the following loop :

For Each ctl In frmSub
msgbox ctl.Name
Next ctl

The loop gave me a list of control names in the order of creation, I
believe. I just hope I could manipulate the order by refering their
names (1-100) of those objects in a loop. For example I named the
first textbox object as 1, and the second one is 2. under their name
property. The
following is my expected logic statement but not working:

For i =1 to 100
Forms!frmMainform!frmSub.Form.=GlobalArrayRecord(i)
next i


Try this:

Dim i As Integer

With frm = Forms!frmMainform!frmSub.Form
For i = 1 to 100
.Controls("" & i) = GloballArrayRecord(i)
Next i
End With

The concatenation of "" with i converts i to a string value, which is
then used as a string index into the form's Control collection.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top