Solved

move curser to beginning of control on click

Posted on 2015-01-28
3
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

756 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