Results 1 to 7 of 7

Thread: Combo problem

  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am trying to find how I can create an event to trap:

    A combo that has items in it, and a combo that is empty. I am trying to fire an event for both if the cursor is inside the textbox of the combo and the user presses the enter key without typing in any entry or selecting an item. The cursor just sits there. I want the user to get a messagebox allowing them to cancel the operation or go back and do something Hope I have explained the problem okay as my head is full of the logic of failed attempts Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try the On Exit event. The event procedure has an argument Cancel that you can set to True if you want to prevent the user from leaving the control.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Hans. I had tried it before and tried it again but it does not work. When the cursor is in the combo textbox, and the return key is pressed, the on exit event does not fire, the cursor just sits there. The only event I found that fires is :

    Private Sub Combo2_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = 13 Then
    If IsNull(Me.Combo2) = True Then
    DoCmd.Beep
    Else
    DoCmd.Beep
    End If
    End If

    End Sub

    However, if the user types in something in the combo textbox it still goes to the first docmd.beep statement. Even though there is text in Combo2 on pressing enter, the control possibly has not updated itself??

    Regards

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Normally, the focus moves to the next control in the tab order when the user presses Enter. Why doesn't that happen here? Is there no next control, or have you set the TabStop property of other controls to No?

  5. #5
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You should have been a detective!! You hit it on the nail. The tab index of the combo was 14, and the only other control available to go to was a textbox with the tab index of 1 which is in the form header. I tried putting another control on the form and the on exit worked. I then removed it and moved the textbox from the header into the detail area, and again the on exit fired. So it looks like it did not like moving to the header, even though the textbox's tabstop was set to yes. Many thanks again. Regards

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Pressing Tab or Enter will only move the focus to another control in the same section, i.e. not from detail section to form header or vice versa.

    If you'd prefer to keep the text box in the form header, you could place a new text (unbound) box in the detail section with Width and Height set to 0. This will allow the user to tab out of the combo box.

  7. #7
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As well as a detective you are now a confirmed mind reader, just what I have done. Many thanks again, Best regards

Posting Permissions

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