Results 1 to 3 of 3
  1. #1
    PicoTTS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    29

    Run Code Only if using Combobox

    Hi,

    I have a combobox that populates based on a query. However, I have to be flexible and allow the user to also manually populate the field with whatever they want. I would like to have my combobox execute a line of code only if the user selects one of the items from the combobox list and do nothing they are entering things manually.

    Is this possible?



    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
    That will be a bit complicated. First, the Limit To List property of the combo box will have to be set to "No". However, you can't set it to
    "No" if the bound column of the combo box is not the same as the first visible column. For example, if the combo box displays a department Name, but the bound column of the combo box is a (hidden) department number, then you can't set the Limit to List to "No".

    If your combo box meets those criteria and you set limit to list to "No", then you can use the After Update event and the ListIndex property of the combo box to determine whether or not an existing row was selected.

    If an existing value was selected, the value if listindex will be >= 0, otherwise it will be -1. So in the After Update event, you could put:

    If comboboxname.listindex >= 0 then
    '.... an existing row was selected, so do something
    endif

  3. #3
    PicoTTS is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    29
    Perfect. That did the trick. Thanks

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

Similar Threads

  1. Replies: 1
    Last Post: 05-04-2013, 12:19 PM
  2. vba code to reference the combobox
    By asv1988 in forum Access
    Replies: 10
    Last Post: 01-16-2013, 02:21 PM
  3. Adding values to a combobox with code
    By jle0003 in forum Access
    Replies: 4
    Last Post: 05-23-2012, 02:15 PM
  4. vba code not working with combobox
    By bopsgtir in forum Programming
    Replies: 9
    Last Post: 02-24-2011, 11:27 AM
  5. Code in combobox, code in text box
    By float in forum Forms
    Replies: 3
    Last Post: 09-29-2010, 07:12 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