Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 14th, 2007, 08:05 AM
Authorized User
 
Join Date: Mar 2006
Posts: 83
Thanks: 1
Thanked 0 Times in 0 Posts
Default Move cursor to beginning of field in form

Hiya folks!

This one must have an easy solution but cant seem to figure it out!

Each time I click on a field in a form (let us say I click in the middle of the field), I want it to automatically move the cursor the beginning of the field (position 1?). Is there a way to do this? I tried using SendKey on the OnGetFocus event for the field with the {Home} but that didnt work.

Thanks!!!
 
Old May 15th, 2007, 02:59 PM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Do this for the 'on focus' and 'on click' events:
------------------------------------------------------
  iFrameSource_Text.SelStart = 0
  My_Textbox.SelLength = 0
------------------------------------------------------

If you want to afterwards be able to click a second time to move cursor possition, your code will need to be a little more complex. Try this (Assuming you're not using the Tag property of the text object already):

-------------------------------------------------------
Private Sub My_Textbox_Click()

'Moves cursor on first click after focus
  If My_Textbox.Tag = True Then
    My_Textbox.Tag = False
    My_Textbox.SelStart = 0
    My_Textbox.SelLength = 0
  End If

End Sub

Private Sub My_Textbox_GotFocus()

'Moves cursor on receiving focus
  My_Textbox.Tag = True
  My_Textbox.SelStart = 0
  My_Textbox.SelLength = 0

End Sub

Private Sub My_Textbox_KeyUp(KeyCode As Integer, Shift As Integer)

'Removes first click when focus gathered by keypress instead of click
  My_Textbox.Tag = False

End Sub
-------------------------------------------------------

Remember if you copy and paste above that you have an text object named My_Text and that you assign an event procedure to the three events the code is written for.


Hope this is what you were looking for.

 
Old May 24th, 2007, 02:10 PM
Authorized User
 
Join Date: Mar 2006
Posts: 83
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi!!! Sorry for the laaaaaaate reply!

Your solution worked perfectly on a Text Box.

And I guess I should have mentioned this ealier, but I need to use this on a combo box, but its not working.

Any clues?

What I am trying to do is the following (in Access 2000): I have a form..... and you know that function where you can search for a record using a combo? Well.... I dont want the user to click on the combo in order to view a list of possible values (in this case "dates"). I want the user to type in a date (using a mask) so that the form can lookup and display the data related to that date.

Thanksssss!
 
Old June 5th, 2007, 04:21 PM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

The problem with a combo box is that most of the properties, including OnClick, refer to the combobox more than the textbox associated with it. To do it you'd have to lay a text box on top of the combo box just short enough to allow the drop down to be clicked and have the value be the same. This has it's own problems as well such as autocomplete when typing in won't work.

It sounds more like you want to type in a date in a text box and have it look up similar to how a drop down can be coded to work.

You CAN do this with a text box control. It has an OnChange routine in which you can code your own lookup procedure. Or you could have a button next to it, use the eyeglass icon if you like, which will perform a lookup based on the date put in the text box. Then use Me.Recordset.findfirst("Where TheDate = "#" & My_TextBox.Value "#").

Does this give you pointers in the right direction? If not, or you're not comfortable with coding custom routines, I'd need more details on what you want.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Move cursor to specific textbox mona_upm84 Excel VBA 3 September 22nd, 2016 10:29 AM
Move cursor to specific textbox mona_upm84 Excel VBA 0 September 29th, 2008 09:35 PM
Move image when cursor approaches sanjana Pro Visual Basic 2005 1 July 19th, 2007 04:55 PM
position cursor at certain field on user form kliu9 Excel VBA 1 January 21st, 2005 06:51 AM
how shall I move the cursor? nerssi Javascript 0 September 21st, 2004 09:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.