Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Afterupdate problem with setfocus on a txtbox in a form

I'm using after update to check to see if a date function is correct. If I
click away inside another txtbox (say txtB) and the test on the previous
txtbox (txtA) failed the txtA.setfocus doesn't work (if you step through it
sets the focus back to txtA but then goes to txtB when the macro finishes)

Private Sub txtA_AfterUpdate()
'test to see if correct date
If checkDate(txtA.value) = false Then
Msgbox "Wrong date"
txtA.SetFocus
End If
End Sub

Any ideas?

Many thanks

James


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Afterupdate problem with setfocus on a txtbox in a form

Instead of using _afterUpdate, try using _Exit.

It has a cancel parm that will keep the user in the textbox.

Private Sub txtA__Exit(ByVal Cancel As MSForms.ReturnBoolean)

'test to see if correct date
If checkDate(txtA.value) = false Then
Msgbox "Wrong date"
cancel = true
End If
End Sub

As a user, I'd rather see a label in the userform (big red letters) that gets
that warning/error message than having to dismiss a msgbox.

And if you have a cancel button on your userform, you'll want to change the
..takefocusonclick property to false. Then the user can click cancel even if the
txtA value isn't a date.



wrote:

I'm using after update to check to see if a date function is correct. If I
click away inside another txtbox (say txtB) and the test on the previous
txtbox (txtA) failed the txtA.setfocus doesn't work (if you step through it
sets the focus back to txtA but then goes to txtB when the macro finishes)

Private Sub txtA_AfterUpdate()
'test to see if correct date
If checkDate(txtA.value) = false Then
Msgbox "Wrong date"
txtA.SetFocus
End If
End Sub

Any ideas?

Many thanks

James


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Afterupdate problem with setfocus on a txtbox in a form

That's great - thanks Dave and have a good weekend

James

"Dave Peterson" wrote:

Instead of using _afterUpdate, try using _Exit.

It has a cancel parm that will keep the user in the textbox.

Private Sub txtA__Exit(ByVal Cancel As MSForms.ReturnBoolean)

'test to see if correct date
If checkDate(txtA.value) = false Then
Msgbox "Wrong date"
cancel = true
End If
End Sub

As a user, I'd rather see a label in the userform (big red letters) that gets
that warning/error message than having to dismiss a msgbox.

And if you have a cancel button on your userform, you'll want to change the
..takefocusonclick property to false. Then the user can click cancel even if the
txtA value isn't a date.



wrote:

I'm using after update to check to see if a date function is correct. If I
click away inside another txtbox (say txtB) and the test on the previous
txtbox (txtA) failed the txtA.setfocus doesn't work (if you step through it
sets the focus back to txtA but then goes to txtB when the macro finishes)

Private Sub txtA_AfterUpdate()
'test to see if correct date
If checkDate(txtA.value) = false Then
Msgbox "Wrong date"
txtA.SetFocus
End If
End Sub

Any ideas?

Many thanks

James


--

Dave Peterson

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
Form, SetFocus and AfterUpdate issue Piers 2k Excel Programming 2 November 8th 05 01:52 PM
looking for a way to make a form Txtbox only visable on Mondays andywalker[_3_] Excel Programming 3 June 25th 05 06:21 PM
txtbox problem [email protected] Excel Programming 0 May 18th 05 05:11 PM
Validateing a txtbox from form Lou Excel Programming 1 April 28th 04 07:25 PM
SetFocus in user form John Tjia Excel Programming 6 February 2nd 04 03:05 PM


All times are GMT +1. The time now is 04:21 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"