+ Reply to Thread
Results 1 to 5 of 5

Find textboxes on a form ?

  1. #1
    SpookiePower
    Guest

    Find textboxes on a form ?

    I Have a lot of Textboxes on my form and from an array I put numbers into these textboxes.
    But it is only some of the textboxes that I want to put numbers in.

    The names of my textboxes are TB1,TB2,TB3,TB4,TB5.........

    My array consist of these numbers 1,2,3,4,5,6......

    I find the correct textboxes using this metod -

    For Each ctl In Me.Controls
    If TypeName(ctl) = "TextBox" Then
    If LCase(Left(ctl.Name, 2)) = "tb" Then
    ctl.Value = ArrayMaterielPlacering(X, 3)
    X = X + 1
    End If
    End If
    Next ctl

    What I want to do is to put the numbers fra the array into the textboxes -
    1 into TB1, 2 into TB2, 3 into TB3, 4 into TB4.....

    But the result came out this way

    TB1 = 1, TB2 = 2, TB3 = 4, TB4 = 3, TB5 = 5, TB6 = 6 ....

    TB3 and TB4 is swapping number ?

    I found out that the metode - For Each ctl In Me.Controls -
    found the textboxes on the form in this way - TB1,TB2,TB4,TB3,TB5,TB6.......

    Hwo can I make the metod - For Each ctl In Me.Controls - find TB3 before TB4 ?

    What I did was to change the place of TB4 and TB3 and then change the names, but is
    it the correct way to do it ? Will there be ploblems later on ?




  2. #2
    Toppers
    Guest

    RE: Find textboxes on a form ?

    Hi,
    One solution is to use the number of the textbox as the value of X
    i.e. for tb3 , x=3: for tb10, x=10

    For Each ctl In Me.Controls
    If TypeName(ctl) = "TextBox" Then
    If LCase(Left(ctl.Name, 2)) = "tb" Then
    x = Right(ctl.Name, Len(ctl.Name) - 2)
    ctl.Value = ArrayMaterielPlacering(x, 3)

    End If
    End If
    Next ctl


    HTH

    "SpookiePower" wrote:

    > I Have a lot of Textboxes on my form and from an array I put numbers into these textboxes.
    > But it is only some of the textboxes that I want to put numbers in.
    >
    > The names of my textboxes are TB1,TB2,TB3,TB4,TB5.........
    >
    > My array consist of these numbers 1,2,3,4,5,6......
    >
    > I find the correct textboxes using this metod -
    >
    > For Each ctl In Me.Controls
    > If TypeName(ctl) = "TextBox" Then
    > If LCase(Left(ctl.Name, 2)) = "tb" Then
    > ctl.Value = ArrayMaterielPlacering(X, 3)
    > X = X + 1
    > End If
    > End If
    > Next ctl
    >
    > What I want to do is to put the numbers fra the array into the textboxes -
    > 1 into TB1, 2 into TB2, 3 into TB3, 4 into TB4.....
    >
    > But the result came out this way
    >
    > TB1 = 1, TB2 = 2, TB3 = 4, TB4 = 3, TB5 = 5, TB6 = 6 ....
    >
    > TB3 and TB4 is swapping number ?
    >
    > I found out that the metode - For Each ctl In Me.Controls -
    > found the textboxes on the form in this way - TB1,TB2,TB4,TB3,TB5,TB6.......
    >
    > Hwo can I make the metod - For Each ctl In Me.Controls - find TB3 before TB4 ?
    >
    > What I did was to change the place of TB4 and TB3 and then change the names, but is
    > it the correct way to do it ? Will there be ploblems later on ?
    >
    >
    >
    >


  3. #3
    Peter T
    Guest

    Re: Find textboxes on a form ?

    > But the result came out this way
    >
    > TB1 = 1, TB2 = 2, TB3 = 4, TB4 = 3, TB5 = 5, TB6 = 6 ....


    The index of controls is set by the order they added to the form, whether
    that was at design stage (typically) or if added at run time. The index's
    and the order will not change and not affected by tab order or position
    order. If you delete a control "later" index's will shift down. I guess you
    added the TB4 to the form before TB3.

    Lot's of ways in code to correct but simple solution for you would be to
    swap names of TB3 & TB4, then swap their relative visual properties.

    TB3 > TBtmp : TB4 > TB3 : TBtmp > TB4

    Regards,
    Peter T


    "SpookiePower" <boxjunk2600@gmail.com> wrote in message
    news:43ca23c9$0$67255$157c6196@dreader2.cybercity.dk...
    > I Have a lot of Textboxes on my form and from an array I put numbers into

    these textboxes.
    > But it is only some of the textboxes that I want to put numbers in.
    >
    > The names of my textboxes are TB1,TB2,TB3,TB4,TB5.........
    >
    > My array consist of these numbers 1,2,3,4,5,6......
    >
    > I find the correct textboxes using this metod -
    >
    > For Each ctl In Me.Controls
    > If TypeName(ctl) = "TextBox" Then
    > If LCase(Left(ctl.Name, 2)) = "tb" Then
    > ctl.Value = ArrayMaterielPlacering(X, 3)
    > X = X + 1
    > End If
    > End If
    > Next ctl
    >
    > What I want to do is to put the numbers fra the array into the textboxes -
    > 1 into TB1, 2 into TB2, 3 into TB3, 4 into TB4.....
    >
    > But the result came out this way
    >
    > TB1 = 1, TB2 = 2, TB3 = 4, TB4 = 3, TB5 = 5, TB6 = 6 ....
    >
    > TB3 and TB4 is swapping number ?
    >
    > I found out that the metode - For Each ctl In Me.Controls -
    > found the textboxes on the form in this way -

    TB1,TB2,TB4,TB3,TB5,TB6.......
    >
    > Hwo can I make the metod - For Each ctl In Me.Controls - find TB3 before

    TB4 ?
    >
    > What I did was to change the place of TB4 and TB3 and then change the

    names, but is
    > it the correct way to do it ? Will there be ploblems later on ?
    >
    >
    >




  4. #4
    kounoike
    Guest

    Re: Find textboxes on a form ?

    this is not the way you are looking for , but
    assuming your textbox number minus 1 matches array index,
    and textbox number start at 3, then this one would work?

    For Each ctl In Me.Controls
    If TypeName(ctl) = "TextBox" Then
    If LCase(Left(ctl.Name, 2)) = "tb" Then
    ctl.Value = ArrayMaterielPlacering(Mid(ctl.Name, 3) - 1, 3)
    End If
    End If
    Next ctl

    keizi

    "SpookiePower" <boxjunk2600@gmail.com> wrote in message
    news:43ca23c9$0$67255$157c6196@dreader2.cybercity.dk...
    > I Have a lot of Textboxes on my form and from an array I put numbers into these

    textboxes.
    > But it is only some of the textboxes that I want to put numbers in.
    >
    > The names of my textboxes are TB1,TB2,TB3,TB4,TB5.........
    >
    > My array consist of these numbers 1,2,3,4,5,6......
    >
    > I find the correct textboxes using this metod -
    >
    > For Each ctl In Me.Controls
    > If TypeName(ctl) = "TextBox" Then
    > If LCase(Left(ctl.Name, 2)) = "tb" Then
    > ctl.Value = ArrayMaterielPlacering(X, 3)
    > X = X + 1
    > End If
    > End If
    > Next ctl
    >
    > What I want to do is to put the numbers fra the array into the textboxes -
    > 1 into TB1, 2 into TB2, 3 into TB3, 4 into TB4.....
    >
    > But the result came out this way
    >
    > TB1 = 1, TB2 = 2, TB3 = 4, TB4 = 3, TB5 = 5, TB6 = 6 ....
    >
    > TB3 and TB4 is swapping number ?
    >
    > I found out that the metode - For Each ctl In Me.Controls -
    > found the textboxes on the form in this way - TB1,TB2,TB4,TB3,TB5,TB6.......
    >
    > Hwo can I make the metod - For Each ctl In Me.Controls - find TB3 before TB4 ?
    >
    > What I did was to change the place of TB4 and TB3 and then change the names, but

    is
    > it the correct way to do it ? Will there be ploblems later on ?
    >
    >
    >



  5. #5
    SpookiePower
    Guest

    Re: Find textboxes on a form ?

    Thanks for your help. I will look at it later today.



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1