Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't get focus back (2003)

    I have a main form - MemberDetail - with a subform - Sector Detail.
    The last control - ie it's the last item in the tab order of the main form before moving to the subform - is called Email and it has an AfterUpdate event on it so the contents can be checked/updated/errored. The check and update work fine. On the error path, I want to output an error, clear the field and set the focus back to the field. The message comes out OK, and the field is cleared but I can't get the cursor back into the field. If the user has tabbed out of the field, the cursor remains in the first field of the subform SectorDetail. If I use the mouse to click into another field on the main form, the cursor remains in whatever field I click into. I am using Me.Email.Setfocus as the VB to try and get the focus back.
    Why won't it reset, please?
    Thanks
    Silverback
    Silverback

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

    Re: Can't get focus back (2003)

    I'd use the Before Update event of the control instead of the After Update event. If the value entered by the user is not correct, set

    Cancel = True

    to cancel the update. The focus will remain on the control until the user either enters a correct value or presses Esc to cancel updating the control.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't get focus back (2003)

    Hans
    Thanks for this; I hadn't appreciated before that the Before Update does allow typing and alteration to the field.
    However, when I do as you suggest, the system errors as shown. What I am trying to do is manipulate the text input into the field and then assign it back as in Me.Email = "string I've just calculated"
    What am I missing, please?
    Silveback
    Attached Images Attached Images
    Silverback

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

    Re: Can't get focus back (2003)

    Don't assign a value. Just use Cancel = True. Let the user take it from there.

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't get focus back (2003)

    Hans
    Sorry to prolong this - I should have said what I am trying to achieve.
    Your 678216 posting detailed what a hyperlink string looked like in an Access control. My user wants to hold email addresses; I don't want to force them to type in mailto: before the address, and if they don't, Access creates a webpage link - in other words, Access puts http:// in front of the user's typed string and it fails when the user clicks the hyperlink (because the page doesn't exist).
    I have written a VB routine to manipulate the string and, if http:// is there, edit it to the format of a mailto: input. as shown in your 678216 posting.
    Thus I do need to be able to write back to the Email field.
    The Before Update routine prevents this, so the After Update event seems to be the answer - but then I can't get the focus back to the Email field.
    What's the best answer to this dilemma, please?
    Thanks
    Silverback
    Silverback

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

    Re: Can't get focus back (2003)

    Use the Before Update event to cancel the update if the value entered by the user doesn't pass the test.
    Use the After Update event to modify the value if it does pass the test.

  7. #7
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't get focus back (2003)

    Oh <img src=/S/doh.gif border=0 alt=doh width=15 height=15> . Sorry to have been so dense.
    All working fine, now.
    Thanks
    Silverback <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    Silverback

Posting Permissions

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