?
Solved

Access - Setting Focus on a Textbox and selecting all the text in that textbox

Posted on 2012-09-06
2
Medium Priority
?
457 Views
Last Modified: 2012-09-06
Hello All,

I have an input Form where I validate the number being input in an AfterUpdate to make sure that the amount input is set multiple for the line being input...

That part works... However, in the Exit Event I have an Event that is Supposed to set the focus back to that input field [Amount].  However when I hit Enter on the ok button of the message box that comes up warning that the amount input is invalid, it is moving the focus to the Next field of the form...

I am wanting it to stay in that [Amount] field AND select all the characters input so that when the user starts typing it types over what's already there.  They shouldn't have to backspace or move the cursor to clear the field to startover.

This is what I have.....
Private Sub Amount_Exit(Cancel As Integer)
Dim strDenomination As String
strDenomination = Me.Denomination

    If Me.txtDenomInputProof <> 0 Then
        MsgBox "The amount entered must be a multiple of " & strDenomination & ".  Please review your input and correct.", vbOKOnly
        Cancel = True
        
        Me.Amount.SetFocus
        
    End If

End Sub

Open in new window

0
Comment
Question by:wlwebb
2 Comments
 
LVL 23

Accepted Solution

by:
irudyk earned 2000 total points
ID: 38374834
Try validating the data using the BeforUpdate event.  So, it would be something like:

Private Sub Amount_BeforeUpdate(Cancel As Integer)
    '--move the code you have in the Private Sub Amount_AfterUpdate() here
    '--then continue with
    Dim strDenomination As String
    strDenomination = Me.Denomination

    If Me.txtDenomInputProof <> 0 Then
            MsgBox "The amount entered must be a multiple of " & strDenomination & ".  Please review your input and correct.", vbOKOnly
            Me.Amount.SelStart = 0
            Me.Amount.SelLength = Len(Me.Amount)
            Cancel = True
    End If
End Sub

Open in new window

0
 

Author Closing Comment

by:wlwebb
ID: 38374839
Worked Perfectly!!!!!!!!!!  Thank you!!
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

840 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