Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Cursor position 1

Status
Not open for further replies.

Costefran

Technical User
Jan 2, 2008
197
GB
Can anyone help with he following

I have a control on my form with format set to

@@@@@@-@@@@@@@@@@

and an input mask set to

>&&&&&&\-&&&&&&&&&&

My problem is when the user clicks on the control ("Named Others_Cost_Codes") the cursor stays wherever the user clicked but I would like the cursor to go to the start of the line. E.g the left - most position

I have tried

Me.Others_Cost_Codes.SelStart=0

but this doesn't seem to work

Many thanks

 
Is the code on the OnEnter event? The control must have focus first for SelStart to work.
 
Yes

I have tried on enter, on focus and on click and nothing seems to work

I have used the same approach on a control with an input mask set to date and it works fine

I should have also poited out that it is a combobox

Thanks
 
Howdy Costefran . . .

In the [blue]On Got Focus[/blue] event of [blue]Me!Others_Cost_Codes[/blue]:
Code:
[blue]   Me!Others_Cost_Codes.SelStart = 0[/blue]

Be sure to disable or delete any other code you had to handle this!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
TheAceMan1

Tried your suggestion but no luck

I entered the following

Me!Others_Cost_Codes.SelStart = 0

and got a bug error. Changed it to

Me.Others_Cost_Codes.SelStart = 0

(notice the change in syntax after me)

stopped getting the bug error but cursor position not defaulting to left

I was checking the sendkeys action and thought that might work if I simulate a press of the Home key but not sure of the syntax


Thanks
 
Just a thought, if Others_Cost_Codes is the name of a field in your table, change the name of the control to, say, cboOthers_Cost_Codes, and try that with the Enter event.
 
got a bug error
Which error message ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Remou
thanks - have tried renaming the control as suggested but still no joy

PHV
If I use
Private Sub Others_Cost_Codes_Enter()
Me!Others_Cost_Codes.SelStart = 0
End Sub
I get the error message "Microsoft Access can't find the Others_Cost_Codes referred to in your expression

if I use
Private Sub Others_Cost_Codes_Enter()
Me![Others Cost Codes].SelStart = 0
End Sub
I don't get the error message but it doesn't work

if I use
Private Sub Others_Cost_Codes_Enter()
Forms![Cost Authorisation Non - Project Form]![Others Cost Codes].SelStart = 0
End Sub
again I don't get the error message but it doesn't work

Many thanks
 
If you are certain of the name of the control, I suggest you recreate your form. Also compact and repair. Decompile probably wouldn't hurt, too. Access is inclined to "lose" controls from time to time.
 
Costefran . . .

For starters I have this working (per your post origination) in A2k with no problem.

As already related to by [blue]Remou[/blue] and the error you posted ...
Costefran said:
[blue]I get the error message "Microsoft Access [purple]can't find[/purple] the Others_Cost_Codes referred to in your expression[/blue]
... [blue]you have a definite naming problem![/blue]

In your post origination you say:
Costefran said:
[blue] . . . when the user clicks on the control ("[purple]Named Others_Cost_Codes[/purple]") the cursor stays wherever the user clicked . . .[/blue]
Then you go on to say:
Costefran said:
[blue]I have tried

Me.[purple]Others_Cost_Codes[/purple].SelStart=0[/blue]
Note the two names in purple in the quotes:
[purple]Named Others_Cost_Codes[/purple]
[purple]Others_Cost_Codes[/purple]

Not quite the same and [blue]the reason for the error![/blue]

Now, in [blue]Remou's[/blue] advice for changing the name, he meant to change the name of the controls [blue]Name[/blue] property! ... not the table.

So to fix this (for now):
[ol][li]Set the controls [blue]Name[/blue] property to [blue]Test[/blue] [red](no quotations please!)[/red].[/li]
[li]In the controls [blue]On Got Focus[/blue], copy/paste:
Code:
[blue]   Me!Test.SelStart = 0[/blue]
[/li]
[li]Be sure to remove any other code in any other event you have to handle this [blue](we don't need any interaction!)[/blue].[/li]
[li][blue]Thats it! Perform your testing![/blue]

If all works well you can revert back to your origional control name! Just be sure the [blue]Name[/blue] property is the same. To be sure you nail it, use the following syntax instead:
Code:
[blue]   Me("[purple][b][i]ControlName[/i][/b][/purple]").SelStart = 0[/blue]
[/li][/ol]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I've got the same problem. None of the suggestions on this thread have helped. My combo box has the input mask

>CCCCCCCCCC;;""

that is, ten characters converted to upper case. When I click on the combo box, the cursor stays where I click.

Very easy to reproduce the problem. Create a form with a combo box and a text box. Set the input mask on the combo box to the above.

Set the OnEnter event procedure for the combo to

Private Sub Combo0_Enter()
Me!Combo0.SelStart = 0
End Sub

I also tried

Private Sub Combo0_Enter()
SendKeys "{HOME}"
End Sub

which doesn't work either. Curiously, this works

Private Sub Combo0_Enter()
MsgBox ActiveControl.Name
SendKeys "{HOME}"
End Sub

and as expected gives the message

Combo0

when I click the OK button, the cursor moves to the beginning of the field. Obviously, I don't want the user to have to click a extra button every time they move into a field so I'm still at a loss on how to do this.

I'm stumped.

 
Hi Again,

I figured out a workaround for this. It's blatant hackery but the user should never know. Do the following:

1. Put a text box on top of the combobox. Only the arrow on the combo box should be sticking out from under the text box. Other then that the text box should perfectly obscure the combo box.
2. Name the text box Combo0Shadow. (assuming that your combo box is named combo0)
3. Set the textbox properties as follows:
TabStop False
BackStyle Transparent
4. Set the OnGotFocus event procedure of the text box to:

Combo0.SetFocus

If you do this then combo0 will never receive the focus from a mouse click. Combo0Shadow will always receive mouse clicks and then pass the focus programmatically to combo0. You can then program the gotfocus event procedure for combo0 (using selstart, sellength etc) so it will behave as you want it to when it receives the focus.

Viola!

It seems like I shouldn't have to do this and I still don't understand the nuances of the problem but as I said "The user will never know."

-Dave

 

I keep telling people the answer to the original problem posted here, and they keep arguing because they think that OnEnter or GotFocus should work (which logically it should, but hey, this is Access) but the simple truth is, for me, in 2000 and 2003, you have to place the code in the OnClick event for the control in order for it to work when you click on it. OnEnter and GotFocus works if you tab into the control, but not if you click on it.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thanks for the reply MissingLinq.

I tried using the On Click event and it doesn't work. Maybe there are some situations where this would work. If you reproduce the problem as described above, it does not. At least in Access 2002. If you disagree, I'd love to hear the details because I'm not too all that fond of my workaround either.

Thanks Again.

-Dave
 
I agree that on click is needed for a text box, but AKAIK this requires a mouse up event in a combo.
 
It is easy to see why.

Build a text box and put all of the events. In the event have it debug.print the event name.

Code:
Private Sub Text0_Click()
  Debug.Print "click"
  MsgBox "click"
End Sub

Private Sub Text0_Enter()
   Debug.Print "enter"
End Sub

Private Sub Text0_GotFocus()
  Debug.Print "got focus"
End Sub

Private Sub Text0_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Debug.Print "Mouse Down"
End Sub

Private Sub Text0_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Debug.Print "Mouse Up"
End Sub

For a text box you will get this

enter
got focus
Mouse Down
Mouse Up ( This is where the cursor pos is set)
click (Then the code moves it to the beginning)

Now change the text box to a combo box. The click does not fire

enter
got focus
Mouse Down
Mouse Up ( This is where the cursor pos is physically set)

but since no event occurs after the mouse up nothing moves it to the beginning
 
The click event for a combo or list only occurs when you click on an item from the list or hit enter when in the list, not when you click in the un pulled down combo.

help file said:
Selects an item in a combo box or list box, either by pressing the arrow keys and then pressing the ENTER key or by clicking the mouse button.
 
If you look closely, Dave, I noted that my answer was for "the answer to the original problem posted here!" That's what you get for hijacking the thread and not paying attention.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top