+ Reply to Thread
Results 1 to 4 of 4

Object won't take focus after AfterUpdate

  1. #1
    Registered User
    Join Date
    12-22-2008
    Location
    Finland
    Posts
    2

    Object won't take focus after AfterUpdate

    please see attached my GUI. I'm using Excel 2003 and VBA 6.5.

    The numbers in the GUI picture show tabindex. cmdSave and cmdUndo are disabled objects unless you click cmdEdit.

    1) I read a bar code into txtBarcode. Bar code reader adds an [ENTER] after the input so focus will move to the next field (cmdEdit). But:

    2) In txtBarcode's afterupdate event I have a routine that checks excel table for matching bar code. If a match is found, identified computer's location and user information are displayed. OK, match found, info displayed, leave txtBarcode.

    3) then automatically I would want the txtBarcode to get the focus again so another barcode could be read without the need for user to use the mouse or tab to jump back into the barcode field.

    Goal: I want txtBarcode to get the focus back when txtBarcode_afterupdate is run.

    Problem: No matter how I try, the focus keeps shifting to the next object in tab index order.

    Sort of solution 1: If a dedicate a command button to set focus on txtBarcode, it works. But I would like it to be automated. Problem with "sort of solution 1": If I would call the "cmdSetFocus" or whatever from txtBarcode_afterupdate, it won't work. Focus shifts to cmdEdit.

    Sort of solution 2: If I edit cmdEdit_enter() like this: "txtBarcode.setfocus" then focus will shift to txtBarcode because there are only 2 objects that can get focus, txtBarcode and cmdEdit. But in this case I cannot click cmdEdit, because it instantaneously transfers focus to txtBarcode.

    I think the problem is about how focus shifts concerning different events, but it has not been easy to figure this out.

    I apologize beforehand that since I (and hopefully most of you) have a Christmas holiday, I won't be online during 12/26 - 1/18. Your tips will still be greatly appreciated.


    Please Login or Register  to view this content.
    Attached Images Attached Images

  2. #2
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    hi,
    Sorry, this may not be much of an answer but could point you in the right direction - I've had this hiccup before but I can't remember exactly how I overcame it...

    I think it involved putting a Label immediately "before" the txtBarcode (in terms of VBE - View - Tab Order), setting the Label up so that it couldn't accept focus, & then using Label.setfocus with the effect of the focus moving back to the txtbarcode field - I think!

    Hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  3. #3
    Registered User
    Join Date
    12-22-2008
    Location
    Finland
    Posts
    2

    [SOLVED] - Object won't take focus after AfterUpdate

    Rob, believe it or not, you gave me a nudge to the right direction! I managed to solve this problem.

    1) I set tabstop = false for cmdEdit but left it enabled. So you only could activate it with a mouseclick, but not by tab press.

    2) Then I added a cmdTemp (tabIndex 1) right next to txtBarcode (tabIndex 0).

    3) Now, what happens is this:
    - Text is entered to txtBarcode. ENTER is inputed.
    - Only option is to move to the object with the next tabindex = cmdTemp.
    - Since cmdEdit has tabstop = false, focus cannot escape to that object.
    - And cmdTemp_enter says: "txtBarcode.setfocus". Voila! focus switches back to the only other available object in the form - in txtBarcode.
    - And cmdEdit is still clickable by mouse if needed.

    Thanks for loaning your brains on this one.


    - Mikael
    Last edited by MPT; 12-23-2008 at 07:37 AM.

  4. #4
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    Pleased I could help - thanks for the feedback :-)

    Rob

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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