Thanks for the suggestion John. I delved deeper and found that Microsoft state that SelStart & SelLength work on the .Text portion of a Combo Box.
Same problem though. Here is the modified code. The Pause (2) is simply a 2 second wait that I have created. The whole field is selected for 2 seconds then the selection drops off.
Code:
Private Sub Box_Enter()
Me.Controls(Screen.ActiveControl.Name).SelStart = 0
Me.Controls(Screen.ActiveControl.Name).SelLength = Len(Me.Controls(Screen.ActiveControl.Name).Text)
Pause (2)
End Sub
As I said, if I insert a break point and then step my way through the lines it works perfectly. There is no other event effecting the field or the form.
I have tested this code on a Text Box and it works great. Convert that Text Box to a Combo and it falls over. Convert it back and all is good again.
This is really baffling.
ps. This is the pause code if you want it.
Code:
Function Pause(intSecs As Integer)
Dim Start As Variant
Start = Timer
Do While Timer < Start + intSecs
DoEvents
Loop
End Function
Ok... problem solved but I would still like to know what is different with "On Mouse Up" and the "On Click" events as far as a Combo Box goes... especially seeing a text box uses "On Click" to achieve the same result.
The user input is for a time entry. I simply want to be able to give a user some choices (drop down list) hence the combo box - and the ability to start typing immediately. Having the user click somewhere within a time field made up of numbers and colons and then expect them to make edits without getting annoyed is not a great call.
I tried it with my staff for a few months and they constantly complained.
Right so when a combo has already got a value, lets say "10:00" and they want to change it to 10:30 so they click on the down arrow or press F4 then click the mouse in the first position after the colon. what should happen should fact that clicked on the value mean that the whole string is highlighted or not.
You may need to look at keyboard behaviour in your options.
This is just a way to fix multiple users requests to have the whole field selected on mouse entry.
And, as simple users (hairdressers and beauty therapists) they have no idea about keyboard behaviors and even less understanding as to what all those keys with all the F's are for.
Easiest solution is to give them what they want. "On Mouse Up" does it.
You might want to consider (perhaps at this point for any future time-editing app) to use a Spin Control in conjunction with a text box . . .
I'm doing that right now with one of my apps and it seems to work quite nicely - that way the user doesn't fuss at all with the direct time-string, and just increments or decrements according to their wishes.
You might want to consider (perhaps at this point for any future time-editing app) to use a Spin Control in conjunction with a text box . . .
I'm doing that right now with one of my apps and it seems to work quite nicely - that way the user doesn't fuss at all with the direct time-string, and just increments or decrements according to their wishes.
I like that idea. My usage though is for a timesheet...
7 days display with 6 login/logoff times per day. Lunch break display as well as dinner break display and total daily hours. That's 63 different variable fields.
...imagine displaying a spinner control for each login/logoff with 15 minute incriments, let alone the better option of a spinner for the hour and one for the minutes.
What I have discovered though is that using the "Button Up" ALWAYS selects the entire field no matter what. To allow for editing if required I have included a simple counter reset in the "Got Focus" event and use it in the "Button Up".
For those who are interested here is the final result...
Code:
Public ClickCount As Integer
Function OnlyTimeKeys(KeyAscii As Integer) As Integer
On Error Resume Next
Select Case KeyAscii
Case 8, 48 To 58 ' allow backspace, periods and digits
Case 13, 27 ' Enter and ESC
me.tbHidden.SetFocus ' very small transparent control object
Exit Function ' Do anything here you want
Case Else: KeyAscii = 0 ' reject everything
End Select
OnlyTimeKeys = KeyAscii
Me.Controls(Screen.ActiveControl.Name).Dropdown ' List of allowed times
End Function
Private Sub SelectAll()
If ClickCount <> 0 Then Exit Sub
'select all of control
Me.Controls(Screen.ActiveControl.Name).SelStart = 0
Me.Controls(Screen.ActiveControl.Name).SelLength = Len(Screen.ActiveControl.Name)
ClickCount = 1
End Sub
' Combo Box example here is obviously named Combo
Private Sub Combo_KeyPress(KeyAscii As Integer)
KeyAscii = OnlyTimeKeys(KeyAscii)
End Sub
Private Sub Combo_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
SelectAll
End Sub
Private Sub Combo_GotFocus()
ClickCount = 0 'resets the counter for SelectAll()
End Sub
My original code does a heap of other stuff which I have stripped out but you get the idea.
...and can you tell that I like one line event coding?
Not to bedevil you now that you have a more-or-less finished product, but if you use a GotFocus pointer to callup the values for each displayed control into a single (or a select few) 'editing' control(s), this would limit your overhead appreciably - which in turn would make a Spin control feasible, I should think.
Not to bedevil you now that you have a more-or-less finished product, but if you use a GotFocus pointer to callup the values for each displayed control into a single (or a select few) 'editing' control(s), this would limit your overhead appreciably - which in turn would make a Spin control feasible, I should think.
It would, however I believe it would actually make it a little more complicated for my users and possibly decrease their interest if they had to click in the time field displayed and then have to work in say a popup that had a time spinner. It would also negate the ability for the field to auto-fill with the current time (to the nearest 15min) to allow a "set and forget" ability. The field dropdown also defaults to this current time for easy user adjustments.
As I said, my code does heaps of other stuff along with the offered solution.
I do like your idea though and will probably utilise it in another venture.
I hear you. Loss of user interest due to a higher input threshold can be a killer. Sounds like this is a case where immediacy for the end-user trumps application efficiency for the developer
Well, cheers from across the "big pond" and all the best for your project Brett