Results 1 to 5 of 5
  1. #1
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727

    On Lost Focus Event

    I have a combo box with a list of values and I am trying to control the prompt that lets the user know when they are typing a value into the cell that is not listed in the drop down box. I basically want the focus to stay on this combo box if they don't select one of the values listed. The scenario that this works with is for when the user presses the tab key to go through the fields in the form. When they get to the combo box they can just type the first letter of the value they want and press tab to auto fill the rest and move on. However, if I let Access' prompt to stop the user from going further if the user decides to click on a button to go to another form or another record within the same form, Access will prompt them to select a valid value from the drop down list, but it will also glitch the hover color of the button to get stuck in that color. So this is the reason why I want to control the prompt with a msgbox instead and that will stop the user and make the hover color of the button they click on not get stuck. Here is the code I have on the Lost Focus event:

    If Me.cmbSubject.Value <> "Payment" Or "Return" Then
    MsgBox ("Please Select Subject From Drop Down List!"), vbCritical, "Requirement"
    Me.cmbSubject.SetFocus


    End If

    The problem I am having is the that Me.cmbSubject.SetFocus seems to be happening right before the On Lost Focus event happens and so the cursor will still move to the next text box after the msgbox pops up. How can I keep the focus on the cmb.Subject so the user cannot move on until they correct the value?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Have you tried the NotInList event or the BeforeUpdate events of the combo
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    My vote is on the BeforeUpdate as you can use its Cancel argument to prevent the update.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Quote Originally Posted by Gicu View Post
    My vote is on the BeforeUpdate as you can use its Cancel argument to prevent the update.

    Cheers,
    Thanks. So I just realized that my prompt will not stop the hover color glitch for the button from happening either. Just to clarify whats happening. User fills out form and gets to the Subject combo box. User types a value that isn't in that list and without moving the cursor to the next text box, they decide to click a button to go to another form or another record without saving. Access will prompt the user to select a value from the list and now the button's hover color is stuck as if the mouse cursor is still hovering over the button. Is there a way to refresh the button so it goes back to normal while the user corrects the Subject value?

    Here is the code I have in the Before Update event:

    Code:
    Private Sub cmbSubject_BeforeUpdate(Cancel As Integer)
    
    
    If (Me.cmbSubject = "Abstract" Or Me.cmbSubject = "Bench Warrant") Then
        Exit Sub
    Else
        MsgBox ("Please Select Subject From Drop Down List!"), vbCritical, "Requirement"
        Cancel = True
    End If
    
    
    End Sub

  5. #5
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Quote Originally Posted by Bob Fitz View Post
    Have you tried the NotInList event or the BeforeUpdate events of the combo
    Thanks for the suggestion. Will be trying the Before Update event.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-07-2020, 06:14 AM
  2. Replies: 18
    Last Post: 07-15-2020, 02:07 PM
  3. Keep textbox in same place when lost focus
    By aytee111 in forum Forms
    Replies: 2
    Last Post: 12-13-2016, 03:59 PM
  4. Replies: 3
    Last Post: 01-18-2014, 02:20 PM
  5. hide a list box on lost focus
    By markjkubicki in forum Programming
    Replies: 2
    Last Post: 08-18-2012, 10:32 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