Results 1 to 6 of 6
  1. #1
    Ally1205 is offline Advanced Beginner
    Windows 7 64bit Access 2000
    Join Date
    Jul 2013
    Posts
    68

    How to automatically overwrite existing text when typing into a combo box?

    Hi,
    I have a combo box for searching records via the client last name. Sometimes I want to search for a number of records this way, one after the other, making some minor changes to the record I am searching for. If I do not amend the record, the lastname shown in the combo box remains highlighted, so that as soon as I click in the combo box to type in a new lastname, the old lastname immediately disappears from the combo box. The problem comes when I amend a record, because if I type something into another textbox on the form, the name in the combo box loses focus and no longer remains highlighted, so when I need to search for a new lastname, I have to physically delete the old lastname showing in the combo box - or highlight the old lastname, so that it disappears as soon as I start typing. This is fiddly if I have to do a lot of searching and amending of records. How do I program the combo box (using its properties) so that as soon as I click in the combo box, the lastname showing is deleted as soon as I click inside the combo box, so I can start typing afresh?



    An even better solution (if it's possible) would be to have a hotkey combination or F-key that would immediately put the focus on the combo box, where all the characters displayed are highlighted, so that I can start typing into that box immediately, without having to use my mouse.

    Many thanks,

    Ally1205
    Last edited by Ally1205; 01-16-2014 at 10:51 AM.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Perhaps the SelText property and some VBA using the Instr() function and the Len() function. Search the help files "ComboBox.SelText Property"

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    How do I program the combo box (using its properties) so that as soon as I click in the combo box, the lastname showing is deleted as soon as I click inside the combo box, so I can start typing afresh?
    This is an unbound combo box, right?
    You could use the Got Focus event of the combo box to clear the value of the combo box

    Something like
    Code:
    Private Sub Combo2_GotFocus()
       Me.Combo2 = Null
    End Sub
    Of course, you would have to use the name of your combo box

  4. #4
    Ally1205 is offline Advanced Beginner
    Windows 7 64bit Access 2000
    Join Date
    Jul 2013
    Posts
    68
    Quote Originally Posted by ssanfu View Post
    This is an unbound combo box, right?
    You could use the Got Focus event of the combo box to clear the value of the combo box

    Something like
    Code:
    Private Sub Combo2_GotFocus()
       Me.Combo2 = Null
    End Sub
    Of course, you would have to use the name of your combo box
    Hi Steve,
    Thank you! Yes, it is an unbound combo box. Your solution above does the job exactly as I had hoped for.

    If anyone can think of a way to configure a hot key which would put the focus on the combo box, that would be an additional improvement. I was wondering of I made the combo box #1 in the tab order, is there a single keystroke that puts the focus on the combo box? Alternatively, can macros be executed with a hot key? If so, would that be a way of doing it?

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You could create a function in a general module that would set focus on the combo. You would have to use the fully qualified name of the control. Something like Forms!frmName!ComboName.Setfocus

    With that you could create a Macro to intercept the keystroke.
    https://www.accessforums.net/access/...mes-40569.html

    You might have difficulty intercepting an F key since Access reserves many of these. Might have to do extra massaging to get it to work.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Open the form that has the combo box in design view. Then open the form module. Paste in the following code
    Code:
    Private Sub Form_Load()
        Me.KeyPreview = True
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
       Me.KeyPreview = False
    End Sub
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
            Case vbKeyF12
          Me.cboALLY.SetFocus
        End Select
    End Sub
    Pressing the [F12] key should set the focus to the combo box .... IF you change the code to the correct combo box name.

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

Similar Threads

  1. Replies: 1
    Last Post: 10-30-2012, 03:50 PM
  2. All text visible while I'm typing
    By viro in forum Access
    Replies: 4
    Last Post: 06-24-2012, 05:11 PM
  3. Overwrite on existing Record
    By waqas in forum Programming
    Replies: 8
    Last Post: 04-03-2012, 12:37 PM
  4. Replies: 3
    Last Post: 08-17-2010, 02:24 PM
  5. Overwrite existing tables
    By magua in forum Import/Export Data
    Replies: 1
    Last Post: 06-21-2010, 11:32 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