Business Solutions:  Access 2003: Cursor Placement In a Text Field.
      By James D. Duncan, CPA


       I had a program fail after years of use by one of my clients. They changed personnel and the new person had a problem. Actually I had a problem, but that is just semantics. The problem was that the new person likes to mouse into some of the fields and the program was made to tab into the fields. If a text field has “cats” in it and you mouse into the text box, the cursor lands where you place it. It may land between the “a” and the “t”. Well, we want it to move to the first position.
       I thought this would be a 5-minute fix. Well, 5 hours is a better guess. I thought I had a routine to do this. It is on one of the 5 or 6 machines I work on. I looked on 3 and gave up. Checked with my normally-reliable programmer friends and they gave me what they liked for the solution. I am presenting to you the end result of this collaboration.
Make a screen with two text boxes and we will begin.




      The solution is so simple that it is embarrassing it took so long to figure it out. Open the properties on the second text box. Click on the event tab and move to the “On Mouse Up” and click on the three ellipses on the right.




     Then enter “Me.Text2.SelStart = 0” in the body of the procedure. That is all there is to it. When they enter the text box, by tab or mouse, the cursor will move to the right position. The 0 position if you will.

 



       Now run the form and enter text into the two text boxes. Mouse into the first box and it stays where ever you click. Then mouse into the second text box and the cursor will jump to the first position to the left. You cannot see that here (but I bet in some future version you will).

 



       Not a long article but I hope it is helpful to anyone who has the same problem and does not have to spend all the time I did on it. Help and I did not get along very well on this. I just was not looking for the right words. But thanks to my programming friends the appropriate words were found.
As usual, I encourage you to help your friends; you may need their help someday. Help a stranger, you may be a stranger in need of help someday. Volunteer your time to help an agency, you will see what riches you have and just never noticed.

 

 

James is a member of the CCOKC and an expert in Access and Excel. Click here to reach James.