Results 1 to 8 of 8
  1. #1
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    SetFocus Trouble??? (Excel 2000)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Loungers

    On May 13, 2003 MS published this MSKB article 237863 but now I am finding another "possible" problem...

    OK I have a data entry form. It has a couple of ComboBoxes, and one of them has an 'Other' category. If the user picks this 'Other' category, I hide a textbox and its label, and display another textbox and its label, to capture what the 'Other' actually mean. I set focus to the new control, and this works OK so far.

    In the AfterUpdate of the newly displayed control, I hide it and its label, redisplay using the Visible = True method, the control I just hid before, and when I set the focus, it goes to 2 controls over in the Tab Order list. Although the Tab Order list is in the correct order, and all I am doing is display and <font color=red> THEN </font color=red> seting the focus...

    Humm???

    I found another article about the Exit Event of the TextBox control, 210734 but I am not sure if they are related.

    Any ideas?

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SetFocus Trouble??? (Excel 2000)

    If you could post a demo, others can test it and see if they come up with a workaround.

  3. #3
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: SetFocus Trouble??? (Excel 2000)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Hans

    Now that is a fantastic idea. OK here is what I need the Loungers to check up for me.

    I have the UserForm, and it has a Race dropdown. In this dropdown I have 'Other'. If the User picks this, a textbox called "tbComplainantsRaceOther" and its label will appear, and a textbox called "tbComplainantsDOB" will hide away.

    Once I finish typing in tbComplainantsRaceOther, I am assumimg that the tbComplainantsRaceOther_AfterUpdate will run, and set the textbox tbComplainantsDOB to visible = True and gives it the focus.

    But instead tbComplainantsRaceOther_AfterUpdate is setting the focus to a control called tbComplainantsAddress2?! The control is 2 away from the textbox "tbComplainantsRaceOther in the Tab Order List?

    Thanks for all. And Please make sure you reply to <font color=red>me</font color=red> and not to Hans
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus Trouble??? (Excel 2000)

    The same thing happens here. I haven't figured out why or a way around it yet.
    Legare Coleman

  5. #5
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: SetFocus Trouble??? (Excel 2000)

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> Legare

    As you see, even if the line in question is remarked out, it still wants to skip the control.

    I am thinking, maybe the control its going to, is the one I drew next in the sequence, and the object internal index is the one its picking. I hate to think this is the case, because that means I have to redraw all these textboxes from scratch again <img src=/S/drop.gif border=0 alt=drop width=23 height=23>

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SetFocus Trouble??? (Excel 2000)

    >> maybe the control its going to, is the one I drew next in the sequence

    No, that isn't true. If you change the tab order property for tbComplainantsDOB from 6 to 7, it will receive the focus OK. But it is very strange, the behavior is not as it should be. It is as if the tab to get out of tbComplainantsRace is processed several times.

  7. #7
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus Trouble??? (Excel 2000)

    Well, I spent some additional time looking at this, and it appears that the .SetFocus method does not work if the form is visable. The following does seem to work:

    <pre>Private Sub tbComplainantsRaceOther_AfterUpdate()
    '/After capturing the Other Race, we need to get back to the DOB.
    With aaMainUserForm1
    '/Hide the Race Other Controls.
    .Hide
    .lComplainantsRaceOther.Visible = False
    .tbComplainantsRaceOther.Visible = False

    '/Show the DOB controls.
    .lComplainantsDOB.Visible = True
    .tbComplainantsDOB.Visible = True
    .Repaint

    '/Set the focus to the new control.
    .tbComplainantsDOB.SetFocus
    .Show

    '/Tell the User.
    Beep
    End With


    End Sub
    </pre>

    Legare Coleman

  8. #8
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Re: SetFocus Trouble??? (Excel 2000)

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> Legare

    This is what I ended up doing. I have uploaded a sample to MS, and they promised me to look into it.

    Great job, and thanks for your help.

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

Posting Permissions

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