UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Combo-box Will Not Keep The Focus    
 
   
accesshawaii
post Mar 27 2012, 01:04 PM
Post #1

UtterAccess VIP
Posts: 4,582
From: From Hawaii - Now in Wisconsin...Am I Nuts?



I have a function that selects list-box values based on the selection made from a corresponding combo-box. I call this procedure from each one of the combo-boxes that is setup to do this. I'm doing this from the "On Click" event. I have tried it from "On Enter" to but still cannot get it to work.

All I'm trying to do is have the combo-box keep the focus, so the user can continue typing names, hitting enter and the selections are highlighted. Below is the routine for this.
Private Sub MyLBSelections ()
CODE
Dim ctl As Control
Dim strCTLRange As String
Dim strMid As String
Dim x As Integer
For Each ctl In Me.Form.Controls
        strCTL = ctl.name
        strCTLRange = Left(ctl.name, Len(strCTL) - 1)
        strMid = Mid(ctl.name, Len(ctl.name), 1)
     Select Case ctl.ControlType
         Case acComboBox
             Select Case strMid
                 Case "C" 'Select the corresonding values in the list-box
                     For x = 0 To Me(strCTLRange).ListCount - 1
                         If Me(strCTLRange).Column(0, x) = Me(strCTL) Then
                             Me(strCTLRange).Selected(x) = True
                         End If

                     Next x

                    Me(strCTL) = "" 'Clear the combo-box for the next selection

    End Select
Next ctl

End Sub
This is just being called like this from the combo-box's "On Click" like this.

MyLBSelections

I have tried tried setting the focus to the control from the control's "On Enter, On Click, and After Update" events with now success e.g. Me.MyControl.SetFocus

Something that should be so simple but yet has me perplexed. Any assistance would be appreciated.

Go to the top of the page
 
+
Jeff B.
post Mar 27 2012, 01:13 PM
Post #2

UtterAccess VIP
Posts: 8,166
From: Pacific NorthWet



(sorry if this is a duplicate ... I suffer from BFF syndrome -- big fat fingers)

Let's see if I understand ...

You have a combobox. You pick an item. That selected item "moves" to a listbox. You want the combobox to retain (?regain) the focus so more items can be "moved" to the listbox. (... and you have more than one of these pairs ...)

Right off the top, I'm wondering if having paired listboxes that let you pick items from the list of "availables" and move them to the list of "selecteds" would accomplish what you're after? I've not run into the combobox/listbox pair, and it seems like it might be a bit more work than the paired listboxes...

JOPO (just one person's opinion)
Go to the top of the page
 
+
Bob G
post Mar 27 2012, 01:14 PM
Post #3

UtterAccess VIP
Posts: 8,104
From: CT



if you are using 2007 have you tried going into access options and setting the behavior there ?
Go to the top of the page
 
+
accesshawaii
post Mar 27 2012, 02:52 PM
Post #4

UtterAccess VIP
Posts: 4,582
From: From Hawaii - Now in Wisconsin...Am I Nuts?



Hi Jeff,

I know what you mean with the moving of items from one combo/list-box to another and how that can cause problems. That's not what I'm doing here. The entry in the list-box that matches the entry that was selected in the combo-box is highlighted. Nothing is moved. This works fine, I've been using this method for quite awhile and never any problems with it. The aspect that I have not been able to figure out is how to retain the focus on the combo-box, so the users can type, get to the entry they want, press enter and then type additional entries. Everything works on this except that the focus is lost whenever enter is pressed. I need the current combo-box to retain the focus.

Hi Bob,

I know there is a global setting for the do not move after enter but that would affect the whole database, which would not work. I need it just on this form. Any ideas?
Go to the top of the page
 
+
Jeff B.
post Mar 27 2012, 03:00 PM
Post #5

UtterAccess VIP
Posts: 8,166
From: Pacific NorthWet



Dan

If I were trying to do what you describe, I'd put code in the combobox's OnExit event that pointed back at the combobox..., something like (untested):

Me!cboMyCombobox.SetFocus
Go to the top of the page
 
+
accesshawaii
post Mar 27 2012, 03:08 PM
Post #6

UtterAccess VIP
Posts: 4,582
From: From Hawaii - Now in Wisconsin...Am I Nuts?



Thanks for the suggestion. I should have pointed out that I have tried about every event using the SetFocus and nothing has worked. When I do it with the "On Exit", the corresponding list-box gets the focus. This is driving me nuts. I mean I understand why it's happening with the Enter because it's assuming that the user is done and wants to move on to the next field but I would think there has got to be a way to sort of by-pass that, so the focus will remain on that control.
Go to the top of the page
 
+
Bob G
post Mar 27 2012, 03:13 PM
Post #7

UtterAccess VIP
Posts: 8,104
From: CT



how about a textbox that gets the focus after the enter is clicked on the combobox. then the only thing the textbox does is have a setting that says when i get focus set the focus to the combobox. You can make the textbox the same color as the background and it should not look like one is there.
Go to the top of the page
 
+
accesshawaii
post Mar 27 2012, 03:17 PM
Post #8

UtterAccess VIP
Posts: 4,582
From: From Hawaii - Now in Wisconsin...Am I Nuts?



Bob, That did the trick, which I'm not understanding why it's working because I tried setting the focus to another combo-box and then redirecting back to the same combo and it didn't work but with this, it does. I already had a text box in place, so I just used that, I just basically did this.

Me.MyTextBox.SetFocus
Me.MyCombo.SetFocus

For whatever reason, it works this way. Thanks.
Go to the top of the page
 
+
theDBguy
post Mar 27 2012, 03:20 PM
Post #9

Access Wiki and Forums Moderator
Posts: 47,914
From: SoCal, USA



Hi Dan,

QUOTE (accesshawaii @ Mar 27 2012, 01:08 PM) *
Thanks for the suggestion. I should have pointed out that I have tried about every event using the SetFocus and nothing has worked. When I do it with the "On Exit", the corresponding list-box gets the focus. This is driving me nuts. I mean I understand why it's happening with the Enter because it's assuming that the user is done and wants to move on to the next field but I would think there has got to be a way to sort of by-pass that, so the focus will remain on that control.

Not sure if this will be applicable or how it will affect your setup but, have you tried something like?

CODE
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = 13 And Screen.ActiveControl.Name = "ComboboxName" Then
    KeyCode = 0
End If

End Sub

Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Go to the top of the page
 
+
Bob G
post Mar 27 2012, 03:21 PM
Post #10

UtterAccess VIP
Posts: 8,104
From: CT



Happy to help.

Go to the top of the page
 
+
accesshawaii
post Mar 28 2012, 08:36 AM
Post #11

UtterAccess VIP
Posts: 4,582
From: From Hawaii - Now in Wisconsin...Am I Nuts?



Hi DBGuy,

Your approach looks interesting. What are keycodes 13 and 0?
Go to the top of the page
 
+
theDBguy
post Mar 28 2012, 09:40 AM
Post #12

Access Wiki and Forums Moderator
Posts: 47,914
From: SoCal, USA



Hi Dan,

QUOTE (accesshawaii @ Mar 28 2012, 06:36 AM) *
Hi DBGuy,

Your approach looks interesting. What are keycodes 13 and 0?

Keycode 13 is the "Enter" key. By assigning 0 to the Keycode, while the focus is in the Combobox, we are essentially telling Access to ignore it if the user hits the Enter key.

Just my 2 cents... (IMG:style_emoticons/default/2cents.gif)
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th May 2013 - 01:20 AM