Results 1 to 7 of 7
  1. #1
    Rickochezz is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    45

    Combo Box Default requires a left mouse click upon opening

    Hello All:

    This one I can't find anywhere. What I need is my combobox to default to the first item in the drop down menu and then left mouse click it to open.



    Here is the code that I have. I have seen that SendKeys is not optimal, so if there is a different way then I am all ears.


    Private Sub Form_Load()
    Me.cboSerial = Me.cboSerial.ItemData(0)
    SendKeys "{F4}"
    End Sub

    Thanks in advance

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I'm not sure I understand. Does the code correctly initialize the combo box? If so, are you wanting to automatically expand the list without the user clicking the expand down-arrow?

    Can you clarify, please?

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Try the following combo button events.

    Code:
    Private Sub Form_Load()
      Me.cboSerial = Me.cboSerial.ItemData(0)
    End Sub
    Code:
    Private Sub cmbSysID_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = acRightButton Then
      Me.ShortcutMenu = False
      Me.cmbSysID.Dropdown
    End If
    End Sub
    Edit: if you don't want all of the rest of the shortcut menu functions to be disabled on that form after the mouse event runs, turn the shortcut menu back on as in

    Code:
    If Button = acRightButton Then
       With Me
         .ShortcutMenu = False
         .cmbSysID.Dropdown
         .ShortcutMenu = True
       End With
    End If
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Rickochezz is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    45
    Click image for larger version. 

Name:	Code2.jpg 
Views:	14 
Size:	86.3 KB 
ID:	25529

    This is what my code with the sendkeys looks like upon loading of form.
    Click image for larger version. 

Name:	Code1.jpg 
Views:	14 
Size:	55.5 KB 
ID:	25530

    This is what I get using Micron's code.

    At this point the user has to physically click on the highlighted selection in the combo box to get the sub form to load with data.

    What I am trying to accomplish is to get the subform to load upon the form opening.

    Is there anyway we can get vba to click on the selection and load the subform?

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    What is a subform? Are you using the Navigation From/Control?

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    At this point the user has to physically click on the highlighted selection in the combo box to get the sub form to load with data.
    Do you have code in the After Update event of the combo box to load data into the subform? If so, you can run that sub from code, just as you would any other sub. Try putting that in the Form_Load sub; it would look something like cboSerial_AfterUpdate

  7. #7
    Rickochezz is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2016
    Posts
    45
    This is the After Update for the combo box


    Private Sub cboSerial_AfterUpdate()
    Me.Requery
    End Sub

    And it works - excellent sir - Thank you so much

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

Similar Threads

  1. Replies: 2
    Last Post: 08-27-2014, 08:19 AM
  2. Disable Mouse Right Click
    By data808 in forum Access
    Replies: 18
    Last Post: 03-10-2014, 05:58 AM
  3. Checking if mouse entered or left button
    By darekg11 in forum Forms
    Replies: 1
    Last Post: 09-28-2012, 05:18 PM
  4. Replies: 0
    Last Post: 09-27-2011, 04:27 AM
  5. Mouse click to open form
    By darryl.charles in forum Programming
    Replies: 0
    Last Post: 09-05-2008, 10:33 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