Results 1 to 4 of 4
  1. #1
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376

    Unbound Combo doesn't behave as expected

    Hello all, I have an unbound combo box on a form that isn't behaving as I would expect and I don't know why. The code is shown below.

    What I expect is that if the Combo51 is left blank and the user clicks off of it, hits "Tab" , etc. then they get the message box (which does happen) however focus is not reset to Combo51 as expected.



    Private Sub Combo51_LostFocus()
    If IsNull(Me.Combo51) Then
    MsgBox "You Must Select Tool Number."
    Me.Combo51.SetFocus
    End If


    End Sub


    What am I missing?

    Thanks



    Dave

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    A control lost focus event can't set focus to itself, otherwise you'd never get off the control.
    You have to set focus somewhere else first.

    The best way to deal with this is two stage - set a default value on the combo, then check for null in the after update event.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Don't know why but this will work if you set the focus to another control on the form first...
    Code:
    Private Sub Combo51_LostFocus()
    If IsNull(Me.Combo51) Then
        MsgBox "You Must Select Tool Number."
        ID.SetFocus
        Me.Combo51.SetFocus
    End If

  4. #4
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    I set focus to another textbox, then back to the combobox and it now works fine.

    Thanks to Minty and davegri

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-17-2017, 11:26 PM
  2. Unbound combobox doesn't pull in ALL records
    By TeamTraveler in forum Forms
    Replies: 9
    Last Post: 05-07-2015, 08:49 AM
  3. Combo box does not work as I expected
    By poppet in forum Forms
    Replies: 11
    Last Post: 04-15-2015, 07:22 AM
  4. Replies: 6
    Last Post: 12-13-2013, 12:38 PM
  5. Replies: 1
    Last Post: 12-16-2009, 04:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums