Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I have a form with a txt box named txtAuditor. on the exit event, i hav some validation checks. i want that if the validation fails, the focus will go back to that tx box. i currectly have if variable=false then txtauditor.value="" txtauditor.setfocus endif this did not work! Any suggestions? -- tkapla ----------------------------------------------------------------------- tkaplan's Profile: http://www.excelforum.com/member.php...fo&userid=2298 View this thread: http://www.excelforum.com/showthread.php?threadid=47113 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() hm... i think you may have to preselect the value that's already there- i know you've set it to " ", but maybe you have to select it? give this a go- if variable=false then txtauditor.value="" 'resets incorrect value - may not be necessary? txtauditor.setfocus 'sets the focus to the text box txtauditor.selStart = 0 'starts the text selection at the start of the incorrect value txtauditor.selLength = 1000 'indicates the last character of the incorrect value (really big, so youre sure you have it- although with the top value being reset- maybe you could error on the side of some smaller number?) endif lemme know if it works, good luck pim -- Pim ------------------------------------------------------------------------ Pim's Profile: http://www.excelforum.com/member.php...o&userid=27565 View this thread: http://www.excelforum.com/showthread...hreadid=471137 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() txtauditor.setfocus 'sets the focus to the text box this is the line that doesn't work. i got around it by setting the cancel to true but i cant figure out why it's not letting me use the setfocus method. -- tkaplan ------------------------------------------------------------------------ tkaplan's Profile: http://www.excelforum.com/member.php...o&userid=22987 View this thread: http://www.excelforum.com/showthread...hreadid=471137 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You said you are using the Exit event, so use the functionality provided:
if variable=false then Cancel = True End if causes focus to remain on the textbox. -- Regards, Tom Ogilvy "tkaplan" wrote in message ... txtauditor.setfocus 'sets the focus to the text box this is the line that doesn't work. i got around it by setting the cancel to true but i cant figure out why it's not letting me use the setfocus method. -- tkaplan ------------------------------------------------------------------------ tkaplan's Profile: http://www.excelforum.com/member.php...o&userid=22987 View this thread: http://www.excelforum.com/showthread...hreadid=471137 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
TK:
The SetFocus doesn't work because txtAuditor already HAS the focus and is in the middle of leaving. It doesn't actually lose the focus until AFTER the exit event has finished. The order of events when you change data in a control is as follows: BeforeUpdate AfterUpdate Exit LostFocus Note that you don't lose the focus until AFTER the event has happened. You have to use the Cancel = True method because that cancels the exit event, thus you don't leave the txtAuditor field & the focus never changes to the next field. Does that make sense?? What you should be using for data validation is the 'Before Update' event. This will let you check the data BEFORE it gets written to the record. Then, because the record hasn't been changed yet, you just use the Undo method for your field if it fails your validation requirements, rather than setting it to "". Here's the finished code: Private Sub txtAuditor_BeforeUpdate(Cancel as Integer) 'Your Validation Code Goes Here, which sets the value of variable If variable = false then Cancel = True Me!txtAuditor.Undo End If End Sub Now, make sure that your validation code tells the user WHY you aren't allowing them to change the data and you're all set! Good luck, Jana |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I remove a Calculated Field from the Pivot Table field list | Excel Discussion (Misc queries) | |||
How to make a field created a part of the Pivot Table Field List? | Excel Discussion (Misc queries) | |||
Unable to change field settings in calculated field in a pivot tab | Excel Discussion (Misc queries) | |||
Linked date field in worksheet defaults a blank field as 1/0/1900 | Excel Worksheet Functions | |||
create formula. 1 field constant and another field varies by inpu. | Setting up and Configuration of Excel |