Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2006
    Posts
    2

    Question Unanswered: Access/Visual Basic Text String Confusion

    Hi All,
    What I want to do sounds simple, but I've spent a lot of hours trying to figure it out with no luck!

    This works ok, and is exactly how I want it:
    Machine1Box1.Left = 567
    It moves my Label called "Machine1Box1" roughly 1 cm from the left side.

    The thing is I want there to be many boxes and many machines (and its not
    just .Left I want to change, I'll be using .Width and .Caption), and so I
    want there to be a string to compile the Label name. For simpilicity of me
    explaining and also undersrtanding I'll cut to the chase!

    If I write:
    Dim strbox As String
    strbox = "Machine1" & "Box1"
    [Text50] = strbox

    Then my temporary text box in Access [Text50] has written in it "Machine1Box1", so far so good.

    However when I add the line:
    strbox.Left = 567
    Hoping the computer will see it as "Machine1Box1.Left" and move it accordingly it throws up an invaild error.
    Its appearing in my temporary box as text ok but its not working how I want it too as a label name string. I'm guessing its due to it being a text element perhaps?
    Any ideas? Hopefully simple please, I'm fairly newbie!

    Many Thanks,

    Jon

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    If I have understood this correctly...
    You cannot do what you want this way (EDIT: actually, you can, see next post ) - depending on what you want to do, you can loop through a set of controls on the page and based on their name, apply a value..
    Example:
    Code:
    Dim ctl As Control
       
        For Each ctl In Me.Controls
            If ctl.Name Like "Machine1*" Then
                ctl.Left = 567
            End If
        Next ctl
    If you clarify what it is you're wanting to do, then we might be able to help you out further
    Last edited by gvee; 04-30-07 at 10:45. Reason: Learnt something new :)
    George
    Home | Blog

  3. #3
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    I think Me(strBox).Left=567 will work.

    BTW: You've been a member for about 15 months, and this is your first post?
    What have you been waiting for?
    Inspiration Through Fermentation

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Oooh RNG is completely correct!
    I never knew it could be done that way
    George
    Home | Blog

  5. #5
    Join Date
    Jan 2006
    Posts
    2
    Thanks for your response! I've managed to get the "For..." statement to work to how I want it too. And I'm now really chuffed with the results! I also managed to strip away lots of repeatitive code I once had, and fix that with "For..." statements. Much appreciated
    The Me(Str).Left = 567 is very much appreciated, I'm sure I've needed it in the passed! (but found a lengthy workaround) and I'll no doubt need it again sometime!

    Re: the 15 months, I didn't realise it was that long! My apologies!
    I mainly use Access/VB on a fairly simple level which is the same with Java, PHP, and Html. I'll try to find some harder questions next time!

Posting Permissions

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