Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 03-22-2019, 04:37 PM
ScottyBee ScottyBee is offline Loop through Multiple Boolean Variables Windows 10 Loop through Multiple Boolean Variables Office 2016
Novice
Loop through Multiple Boolean Variables
 
Join Date: Mar 2019
Location: Portland, Oregon
Posts: 12
ScottyBee is on a distinguished road
Default Return Focus to textbox if Validation Fails

Hello Guessed and GMaxey,


I have implemented both of your ideas into my Validation process but am having problems with the focus being returned to my first texbox (txt1) if validation fails. Currently, the focus moves to my second textbox (txt2). I am using the TAB key to advance the cursor from textbox to textbox. Maybe it is the end of the week and I am missing something easy.



Here is my code for the Validate procedure I have created:
Code:
Sub Validate(ControlNumber As Integer)
Select Case ControlNumber
    Case 1
    'number only
    If Not IsNumeric(txt1.Text) Then
        MsgBox ("Must be a Number")
        txt1.SetFocus
    End If
    'Case 2,3,4,5,6,7,8 to follow
End Select
End Sub
Here is the code for the txt1 AfterUpdate event:


Code:
Private Sub txt1_AfterUpdate()
    txt1.BackColor = vbWhite
    Validate (1)
End Sub
If I run the form and type in a letter, the code detects the error and displays the message box as planned. However, when I click OK, the focus is not returned to the txt1 control. It moves to the txt2 control meaning the user could ignore the error.


How do I get the focus to return to txt1 and keep it there as many times as necessary until user puts in only numbers? Maybe I am using the incorrect event or missing something easy? Thanks
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate template-based letter with multiple variables shallaes Word VBA 5 07-12-2018 12:18 AM
Multiple Problems with a loop Radtastic10 Excel Programming 3 06-09-2017 09:38 AM
Testing multiple values of two independant variables and charting results sgcannon Excel 0 10-20-2015 10:10 AM
Array to iterate through variables and trap blank variables Marrick13 Word VBA 5 08-04-2015 06:19 AM
Same values of variables in word add-in are being shared across multiple document naq.abbas@gmail.com Word 0 01-13-2014 10:41 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:19 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft