Solved

move curser to beginning of control on click

Posted on 2015-01-28
3
147 Views
Last Modified: 2015-01-28
hello,

I got this code from somewhere here on this site, but the other code that I got to require the field is now being bypassed and doesn't seem to work.

Is there any other way to move the curser to the beginning of the field?  I have tried SendKeys, but as we know that turns off the numlock...

Private Sub ZipCode_Click()

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

End Sub

Private Sub ZipCode_GotFocus()

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

End Sub

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

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

End Sub



Code to require field:

If CheckRequired1(Me) = False Then
    Cancel = True
    Exit Sub


'' this code goes in a STANDARD module.  It will not be reusable if you put it in the CLASS module of a form
Public Function CheckRequired(frm As Form) As Boolean
    Dim ctl As Control
    For Each ctl In frm.Controls
        If ctl.Tag = "REQ" Then
            If ctl.Value & "" = "" Then
                MsgBox ctl.Name & " is required.  Please enter a valid value.", vbOKOnly
                ctl.SetFocus
                CheckRequired = False
                Exit Function
            End If
        End If
    Next ctl
   
    Set ctl = Nothing
    CheckRequired = True
End Function
0
Comment
Question by:Ernest Grogg
3 Comments
 
LVL 36

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40575562
I don't do stuff like this in my apps.  I prefer to let the user make his own choice.  The users know that if they tab from control to control, the entire text of a field is selected and they can just type to replace it.  But if they click into a control, then the insertion point becomes where they clicked.  Also for this reason, I rarely use Input Masks.  Input Masks are extremely annoying unless you tab into a control.  When you click, you are almost certainly going to have an issue.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40575784
<No Points wanted>
I have tried SendKeys, but as we know that turns off the numlock...
Not always, ...sendkeys should only be used as a last resort, and support for it ma be dropped a some point, ...but I have never had an issues with code like what you posted. (FWIW)

The other issue here is that systems like this create non-standard functionality...
Where every other program functions in the same way, ...but only your app will function another way.

What if the user just wants to change the third letter/number?, ...suppose they just need to add a letter/number on the end?

I have seen situations whee this is needed for one filed, ...but not for all.

JeffCoachman
0
 

Author Comment

by:Ernest Grogg
ID: 40575880
I guess the real answer is to drop it and let them move the curser...just trying to help them with a way to do it...

I personally wouldn't do it, but as customer service goes we like to please them...

Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question