View Full Version : Focus/Enter events


David R
01-30-2002, 10:04 AM
Preface: I'm using Acc2k and it's possible this has changed, however the help files lie in this case (always a possibility).

I'm trying to simplify my code somewhat, because right now there is some duplication. I have to use the Click and the GotFocus events to set my positioning (it applies to other actions too, but this is a non-trivial example).

Private Sub TelephoneNum_GotFocus()
Me.ActiveControl.SelStart = 6
End Sub

Private Sub TelephoneNum_Click()
Me.ActiveControl.SelStart = 6
End Sub


The help file says when a mouse click is used to change focus, the events are fired in the following order for the 2nd control (from find out when events occur) : Enter -> GotFocus -> MouseDown -> MouseUp -> Click

I know I can step through the code to see when events fire, but we're getting kicked out early today due to the weather.

David R

Jack Cowley
01-30-2002, 10:44 AM
If you are trying to reduce the amount of code I am not sure that you can. If you tab into the field the On Enter or On Got Focus will set your cursor position but if the user clicks on the field the cursor position will be determined by where the cursor is when they click. Since you have to cover all possible ways that a user can 'enter' a field I think that you are going to have to cover all the bases with code....

Fornatian
01-30-2002, 12:34 PM
Normally what I do if I have repeating code is either call the sub routine or build a specific one that does the job for me:


Private Sub TelephoneNum_GotFocus() Me.ActiveControl.SelStart = 6
End Sub
Private Sub TelephoneNum_Click() TelephoneNum_GotFocus
End Sub


OR

Private Sub TelNumStart()
Me.ActiveControl.SelStart = 6
End sub

Private Sub TelephoneNum_Click()
TelNumStart
End Sub

Private Sub TelephoneNum_GotFocus()
TelNumStart
End Sub



Either way you need to include code for each event.



[This message has been edited by Fornatian (edited 01-30-2002).]

David R
01-31-2002, 07:03 AM
Okay. I suppose perhaps Enter/GotFocus get called but then get superseded by the Click event. Either way it's poor documentation, but I wanted to check that it wasn't just my computer.

What I was trying to avoid was calling from Click because it fires _every_ time you click in the control. This makes it difficult to position your cursor with the mouse, as it always jumps back to the nth position.
Double clicking works, but this is counter-intuitive.

Thanks,
David R

[This message has been edited by David R (edited 01-31-2002).]