Results 1 to 6 of 6
  1. #1
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317

    Closing a combo box

    Folks



    This one is driving me up the wall. I have several combo boxes on my form, which are locked depending on the value entered in another field. When the user clicks on one of these combo boxes, a message pops up telling them they can't make any changes. So far so good. But if they've clicked on the down-arrow on the right of the combo box, once they've OK'd the message the full dropdown list is displayed. How on earth do I stop this happening or at least close the list again programmatically?

    I have variants of this in my On Mouse Down events:

    Code:
     
    If Me!Status.Value = "Cancelled" Then
        MsgBox "You cannot amend a record for a cancelled document." _
            , vbInformation
    End If
    Remster

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Set the cbo Enabled property to False instead of the Locked property to True.

  3. #3
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    Quote Originally Posted by RuralGuy View Post
    Set the cbo Enabled property to False instead of the Locked property to True.
    The thing is, I want any previously selected values to remain visible, so I don't want the box to be greyed out.

  4. #4
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    The other problem is that if the combo boxes can't receive the focus, my message box won't pop up (this has occurred to me just now because I've tried setting Locked to True and Enabled to False, which avoids the greying out).

    I really need F4 or Escape or something to fire when the message is OK'd (just adding SendKeys as an extra line of code doesn't work).

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You should be able to close the DropDown by simply moving the focus to another control.

  6. #6
    Remster is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    317
    It's all right, I've sorted it now. What I didn't tell you is that as well as my On Mouse Down event I have a corresponding On Key Down event. I'd forgotten either to exempt the F4 key or to add the 'SendKeys "{F4}"' instruction to this:

    Code:
        If Not KeyCode = vbKeyF4 Then
            If Me!Status.Value = "Cancelled" Then
                MsgBox "You cannot amend a record for a cancelled document." _
                    , vbInformation
                SendKeys "{F4}"
            End If
        End If
    Without the 'SendKeys "{F4}"' instruction, the dropdown list is left open. Without the line 'Not KeyCode = vbKeyF4', the 'SendKeys "{F4}"' instruction in the other event creates an eternal loop. D'oh!

    Sorry for littering your website with these petty issues.

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

Similar Threads

  1. Closing and saving a form
    By Lxmanager in forum Forms
    Replies: 14
    Last Post: 11-21-2010, 02:04 AM
  2. Prevent a form from closing
    By ksmithson in forum Forms
    Replies: 0
    Last Post: 07-15-2010, 12:49 PM
  3. Closing the application with some timer
    By reachvali in forum Programming
    Replies: 1
    Last Post: 05-18-2010, 11:28 PM
  4. Compacting When Closing?
    By Sean04 in forum Access
    Replies: 5
    Last Post: 03-19-2010, 01:16 PM
  5. Closing a Form Problem
    By MuskokaMad in forum Forms
    Replies: 2
    Last Post: 03-18-2010, 05:58 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