Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Location
    New York, New York, USA
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Forms and Subforms (Access 97)

    I have a Books database, which contains a form that has a combo box from which I can chose an author

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Forms and Subforms (Access 97)

    Recommend use combo box's On Enter event. Example:
    <pre>Private Sub Combo1_Enter()
    With Me.Combo1
    .SelStart = 0
    .SelLength = Len(.Text)
    End With
    End Sub
    </pre>

    HTH

  3. #3
    Star Lounger
    Join Date
    Apr 2002
    Location
    New York, New York, USA
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms and Subforms (Access 97)

    Thanks for your suggestion, but I am not totally confused. I added you code as suggested. When I put a breakpoint on the End With stm, the name in the combo box is selected. When I remove the breakpoint, and rerun, the name is not selected! Is there something going on I don't understand?

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms and Subforms (Access 97)

    Seems to me that you don't need code. Set the Auto Expand property of the combo to yes and to select the combo, click on his label instead of the combo itself or use a shortcut key.
    Francois

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Forms and Subforms (Access 97)

    The problem here is:

    (1) The OnEnter and OnGotFocus events are processed before the OnClick event.
    (2) The OnClick event is entirely processed by Access (or Windows), and not passed to VBA. You can test this by putting code in the OnClick event like Beep or MsgBox "Hello". Nothing happens. This is in contradiction with the help file. The standard action of clicking in a combo box is to place the insertion point where you click.

    If you single-step the code, you momentarily see the text being selected, but if you click in the combo box after the code is finished, the selection is cancelled.
    If you just run the code, the text is being selected and deselected so fast (I suspect) that you don't even see it.

    I don't know a solution for this, except suggesting your users not to click in the combo box, but to activate it by using the Tab key or by typing the shortcut key (if you have assigned one).

  6. #6
    Star Lounger
    Join Date
    Apr 2002
    Location
    New York, New York, USA
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Forms and Subforms (Access 97)

    Thank you everyone for your help. By clicking on the combo box caption, the current name is selected, and things work just fine. In fact, as Francois suggested, I don't need any code, just setting the AutoExpand to Yes does it.
    I did find, though, that MsgBox("Hello") in the Click event of the combo box was executed, even when I did NOT click the combo box. I am stilled puzzled by Access, but you solved the problem.
    Incidentally, in Access' Solutions Database "Using two subforms on a form", MS handles the problem by adding a Combo1=Null statement in the On Current event of the form. This erases the name immediately after you press enter. To keep the name you're working with on display, they add a text box to display the contents of the combo box. That seems a klutzy way to do it. With you help I was able to implement a much cleaner solution.

Posting Permissions

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