Solved

move curser to beginning of control on click

Posted on 2015-01-28
3
127 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
Comment Utility
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
Comment Utility
<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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

16 Experts available now in Live!

Get 1:1 Help Now