Thread: Access97

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    North Yorkshire (U.K.)
    Posts
    64
    Rep Power
    14

    Access97


    The procedure below is supposed to loop through the labels on a form intil it gets to a specific one (in this case a label named txt11000). I'm using Access97 but every time I try to run this, it gives a non specific error.
    Also, the step value on the for statement gives an error, however, if I set it to -50, then it doesn't give an error!!

    ANY IDEAS???

    Private Sub settextboxes( i As Integer)
    Dim j As Integer
    For j = 700 To 2000 step 50
    Set Label = CommandBars.FindControl(msocontrolLabel, "txt" + i + j, , True)
    If j = 1000 Then
    'Set backcolor of the label named txt11000
    End If
    Next j
    End Sub
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Location
    NJ, USA
    Posts
    91
    Rep Power
    13
    I suspect your problem is in the order of precedence. In the line starting "Set Label" you start by concatenating a string. The rest of the operation will read this as a string.

    Thusly, you are not adding the values of i and j, but rather taking their string equivalents.

    If

    i = 100
    j = 700

    then

    "txt" + i + j will result in "txt100700"

    Try this

    For j = 700 To 2000 step 50
    x = i + j
    Set Label = CommandBars.FindControl(msocontrolLabel, "txt" + x, , True)


    Walt
    Last edited by Waltjp; June 7th, 2002 at 03:23 PM.
  4. #3
  5. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Also, remember that "+" is not really a concatenation operator. Sometimes Access will through errors because you are adding mis-matched types. I believe the VBA concatenation operator is "&", so try changing the line in question to:
    Code:
    Set Label = CommandBars.FindControl(msocontrolLabel, "txt" & x, , True)
    The real n-tier system:

    FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

    Amazon wishlist -- rycamor (at) gmail.com
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Location
    NJ, USA
    Posts
    91
    Rep Power
    13
    I agree on the '+', though JavaScript does allow it.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    North Yorkshire (U.K.)
    Posts
    64
    Rep Power
    14
    Thanks for the replies, I eventually got it to work using the following...

    Me.Form.Controls("txt" +
    CStr(i) +
    CStr(mytimestr2)).BackColor =
    RGB(0, 0, 0)

IMN logo majestic logo threadwatch logo seochat tools logo