+ Reply to Thread
Results 1 to 5 of 5

Register backspace within a combobox change event

  1. #1
    Registered User
    Join Date
    06-11-2009
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    63

    Register backspace within a combobox change event

    Hi all,
    I have a combobox that reacts when the user changes its contents. It contains a list of all employee names and searches a database for all entries containg the name of that employee.

    To me it seems pointless to search when backspace is pressed since the combobox will automatically return the values for the same person. For example

    You select John Smith and decide to search for John Anderson. Every time you press the backspace button to delete the letters s m i t h the macro updates (change event) and gives me the data entries for John Smith.

    Is there a way to register the backspace event within the Private Sub Combobox_Change Event so I can prevent it from updating?

    Much obliged for the help
    Nick

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Register backspace within a combobox change event

    One of the many reasons I would never recommend using a change event to trigger code like that. I suggest you either use the Exit event instead or use an additional button to actually retrieve the data.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    06-11-2009
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Register backspace within a combobox change event

    Quote Originally Posted by romperstomper View Post
    One of the many reasons I would never recommend using a change event to trigger code like that. I suggest you either use the Exit event instead or use an additional button to actually retrieve the data.
    So how do I use the exit event?

    Changing Private Sub ComboBox1_Change() to Private Sub ComboBox1_Exit() gives me an error message.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,978

    Re: Register backspace within a combobox change event

    You should never write the event header yourself, unless you are sure you know the correct syntax. At the top of the main code window you should see two dropdowns (one on the left, one on the right). Select Combobox1 from the left hand one, and Exit from the right hand one, and you should see the event procedure stub created for you.

  5. #5
    Registered User
    Join Date
    06-11-2009
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Register backspace within a combobox change event

    Quote Originally Posted by romperstomper View Post
    You should never write the event header yourself, unless you are sure you know the correct syntax. At the top of the main code window you should see two dropdowns (one on the left, one on the right). Select Combobox1 from the left hand one, and Exit from the right hand one, and you should see the event procedure stub created for you.
    Yup, I was missing a piece. Just got it to work. Thanks!

    I'm still having some issues with deleting with the combobox itself but those seem to occur regardless of the event type I use (change or exit). Instead of deleting the text gets selected and no deletion process is actually displayed. I'll have to work on that a bit.

    EDIT: I found a simple workaround to avoid updating when backspace is pressed. I just store the initial value and check if its last characters are being removed.
    Last edited by Newbie_Nick; 08-03-2010 at 07:32 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1