Solved

move curser to beginning of control on click

Posted on 2015-01-28
3
134 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 34

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TRIM a textbox value MS Access 10 23
Export  Access Query To Excell 16 44
View vs Edit mode enhancements 12 40
MS Access XML API HTTP POST Call Object Send Not Working Correctly 15 34
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now