Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Wes Wes is offline
external usenet poster
 
Posts: 26
Default Accessing a control

Hi, I've created a number of textboxes using the following code.

For Count = 1 to 30
Set MyTBox = MyControl.Controls.Add("Forms.textbox.1")
With MyTBox
.Width = 150
.Height = 20
.Top = 20 * Count - 13
.Left = 2
.name = "TBox" & Count
.Visible = True
End With
Next

I now want to access say the fifth box (TBox5)

I have a string (BoxName) with the name of the box TBox5 or I could use an
integer variable to indicate that I want the fifth box, but how do I refer to
this box? I tried:

MyTBox.BoxName.value = ... but this does not work,
and I tried:
MyTBox(5).value = ... this too does not work. What am I missing?

Again, thanks for your help in advance!!!



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Accessing a control

Hi Wes,

As you are creating the TextBoxes on the fly, it's not so easy to address
them in your code. Here is one method you can use:

Dim Cont As Control
For Each Cont In myForm.Controls
If Cont.Name = "TBox5" Then
Cont.Value = "My Value"
End If
Next

I hope this helps,

Sean.
--
(please remember to click yes if replies you receive are helpful to you)


"Wes" wrote:

Hi, I've created a number of textboxes using the following code.

For Count = 1 to 30
Set MyTBox = MyControl.Controls.Add("Forms.textbox.1")
With MyTBox
.Width = 150
.Height = 20
.Top = 20 * Count - 13
.Left = 2
.name = "TBox" & Count
.Visible = True
End With
Next

I now want to access say the fifth box (TBox5)

I have a string (BoxName) with the name of the box TBox5 or I could use an
integer variable to indicate that I want the fifth box, but how do I refer to
this box? I tried:

MyTBox.BoxName.value = ... but this does not work,
and I tried:
MyTBox(5).value = ... this too does not work. What am I missing?

Again, thanks for your help in advance!!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Accessing a control

Just use

Me.Controls("TBox5").Text = ...

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Wes" wrote in message
...
Hi, I've created a number of textboxes using the following code.

For Count = 1 to 30
Set MyTBox = MyControl.Controls.Add("Forms.textbox.1")
With MyTBox
.Width = 150
.Height = 20
.Top = 20 * Count - 13
.Left = 2
.name = "TBox" & Count
.Visible = True
End With
Next

I now want to access say the fifth box (TBox5)

I have a string (BoxName) with the name of the box TBox5 or I could use an
integer variable to indicate that I want the fifth box, but how do I refer
to
this box? I tried:

MyTBox.BoxName.value = ... but this does not work,
and I tried:
MyTBox(5).value = ... this too does not work. What am I missing?

Again, thanks for your help in advance!!!





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2007 Form Control/ActiveX Control font difference Nikko963 Excel Discussion (Misc queries) 0 April 15th 09 04:21 PM
Issue when accessing the property/method of a Calender control Anand Excel Programming 0 January 12th 07 05:36 AM
accessing excel combo box control data from vb .net CoolCyber Excel Programming 2 October 26th 05 04:20 PM
Problem accessing control in another form johncassell[_17_] Excel Programming 5 August 1st 05 08:16 PM
Accessing ActiveX Controls using VBA - can't use Control.Name to access. Rob Bovey Excel Programming 2 July 30th 03 09:11 AM


All times are GMT +1. The time now is 11:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"