PC Review


Reply
Thread Tools Rate Thread

Accessing a control

 
 
=?Utf-8?B?V2Vz?=
Guest
Posts: n/a
 
      27th Oct 2007
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 With Quote
 
 
 
 
=?Utf-8?B?U2VhbkMgVUs=?=
Guest
Posts: n/a
 
      27th Oct 2007
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!!!
>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      27th Oct 2007
Just use

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

--
---
HTH

Bob

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



"Wes" <(E-Mail Removed)> wrote in message
news:B1D3E004-E10C-4D82-A35A-(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem accessing control from inside other control Nathan Sokalski Microsoft ASP .NET 3 10th Jan 2008 05:17 AM
Accessing a control's properties from a user control RSH Microsoft VB .NET 0 18th Dec 2006 04:31 PM
Accessing values of a control which is in a user control =?Utf-8?B?U3Jpbmk=?= Microsoft ASP .NET 1 2nd Nov 2006 08:53 AM
User control accessing outside control tshad Microsoft ASP .NET 3 19th May 2006 04:34 PM
Accessing a parent web form control from within a nested user control? Roy Microsoft ASP .NET 1 10th Feb 2005 07:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:16 PM.