Results 1 to 3 of 3
  1. #1
    Yodo is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2017
    Posts
    12

    Сlose dropdown list in combobox On Mouse Move event in VBA?

    I'm developing a user form in Access. I have this code to open dropdown menu when mouse is on combobox:
    Private Sub cmbx_ID_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Me.cmbx_ID.SetFocus
    Me.cmbx_ID.Dropdown
    End SubBut I want to close dropdown menu when mouse is away from the combobox (now to close the form he should either select an item in dropdown menu or click on the form). I found that I can create a button and close the form when mouse is on this button:
    Private Sub Frame1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    CommandButton1.SetFocus


    SendKeys "{esc}", True
    End Subbut that not what I'd like.

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    Here's a variation on your idea. Make the textbox so big (and invisible) that moving the mouse off the combobox will always trigger it's mousemove event.

    Attachment 28697Attachment 28698
    Code:
    Option Compare Database
    Option Explicit
    Dim Working As Long
    Private Sub cboBrand_AfterUpdate()
        Me.Filter = "[Brand] = '" & cboBrand & "'"
        Me.FilterOn = True
    End Sub
    
    
    Private Sub cboBrand_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        cboBrand.SetFocus
        cboBrand.Dropdown
        Working = 1
    End Sub
    
    
    Private Sub cmdBig_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Working = 1 Then
            cmdBig.SetFocus
            SendKeys "{ESC}"
            Phone.SetFocus
            Working = 0
        End If
    End Sub

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    To execute something, when moving off of a Control, like this, you'd normally use the MouseMove event of the Section (Detail, Header, Footer) that the Control resides on.

    If it's on the the Detail Section, for example

    Code:
    Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'Code goes here
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 14
    Last Post: 09-15-2017, 11:25 AM
  2. Mouse Move Event - End if Mouse not Hovering
    By Tandem in forum Programming
    Replies: 3
    Last Post: 05-24-2016, 12:38 PM
  3. Update Database on Lose Focus event
    By sgroth in forum Forms
    Replies: 2
    Last Post: 06-11-2011, 07:31 PM
  4. On Mouse Move, Flickering
    By 95DSM in forum Programming
    Replies: 1
    Last Post: 01-04-2011, 08:35 AM
  5. combobox.dropdown event not working after error
    By perlyman in forum Programming
    Replies: 1
    Last Post: 04-02-2010, 06:55 PM

Tags for this Thread

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