Results 1 to 4 of 4

Object won't take focus after AfterUpdate

Threaded View

  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.


    Private Sub UserForm_Initialize()
        cmdSave.enabled = false
        cmdUndo.enabled = false
        txtBarcode.setfocus
    End Sub
    
    Private Sub txtBarcode_enter()
        txtBarcode.value = ""
    End Sub
    
    Private Sub txtBarcode_afterupdate()
        'search in the excel for a cell matching txtBarcode.value
        'found it, copy cell1 to lblComputername, copy cell2 to lblComputerSN etc
        'irrelevant sheet editing and find function code removed from sample
    End Sub
    
    Private Sub cmdEdit_click()
        cmdSave.enabled = true
        cmdundo.enabled = true
    End Sub
    
    Private Sub cmdSave()
        'put txtBuilding.value into cell 6, txtRoom.value into cell 7 etc
        'irrelevant sheet modification code removed from sample
        cmdSave.enabled = false
        cmdUndo.enabled = false
        txtBarcode.setfocus 'This WORKS, focus is shifted to txtBarcode
    End Sub
    
    Private Sub cmdUndo()
        cmdSave.enabled = false
        cmdUndo.enabled = false
        txtBarcode.setfocus 'This WORKS, focus is shifted to txtBarcode
    End Sub
    Attached Images Attached Images

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