Solved

move curser to beginning of control on click

Posted on 2015-01-28
3
165 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 38

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

626 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