Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default set focus on txt field


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default set focus on txt field


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default set focus on txt field


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default set focus on txt field

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default set focus on txt field

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I remove a Calculated Field from the Pivot Table field list TheTraveler Excel Discussion (Misc queries) 2 April 9th 10 06:55 PM
How to make a field created a part of the Pivot Table Field List? drhell Excel Discussion (Misc queries) 0 January 29th 07 11:13 PM
Unable to change field settings in calculated field in a pivot tab Mike Excel Discussion (Misc queries) 0 September 25th 06 07:45 PM
Linked date field in worksheet defaults a blank field as 1/0/1900 AmnNkD Excel Worksheet Functions 2 September 12th 06 05:42 PM
create formula. 1 field constant and another field varies by inpu. telnettech Setting up and Configuration of Excel 2 February 2nd 06 11:09 PM


All times are GMT +1. The time now is 12:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"