#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default setfocus

I have a text box which receives a 10 digit number.
A fucntion is then called and the validity of the number is checked.
If the number is invalid the bacground colour of the text box is changed to
RED and the focus and Selection for the text box is re-set

Sub ChangeTextBoxColour()
'change text box colour to show alert
frmHotlist.txtCardNumber.BackColor = RGB(255, 0, 0)
frmHotlist.txtCardNumber.SetFocus
frmHotlist.txtCardNumber.SelStart = 0
frmHotlist.txtCardNumber.SelLength = 10

End Sub

This initially worked fine until I inserted another text box for the
insertion of a date the validity of the text is checked using IsDate()
This then calls a subroutine to change the text box colour and reset the
focus on the text box (all incidentally to speed up entering data into the
form)

HOWEVER.
The second setfocus refused to work! as did the selection process.
when I went back to my first text box and rem out the code of the setfocus
to see if the second set focus would work then nothing happened THEN AFTER
putting the code back to the way it was the FIRST TEXT BOX will not work
either!
Is anyone aware it there is some kind of bug in the software or should I be
doing something else?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default setfocus

Not sure what exactly is going on, but I find that sometimes you have to
focus another control first
before moving the focus to the control you really
want to get the focus.

So you want control A and do:

ControlB.SetFocus
ControlA.SetFocus

RBS

"Dean Reardon" <Dean wrote in message
...
I have a text box which receives a 10 digit number.
A fucntion is then called and the validity of the number is checked.
If the number is invalid the bacground colour of the text box is changed
to
RED and the focus and Selection for the text box is re-set

Sub ChangeTextBoxColour()
'change text box colour to show alert
frmHotlist.txtCardNumber.BackColor = RGB(255, 0, 0)
frmHotlist.txtCardNumber.SetFocus
frmHotlist.txtCardNumber.SelStart = 0
frmHotlist.txtCardNumber.SelLength = 10

End Sub

This initially worked fine until I inserted another text box for the
insertion of a date the validity of the text is checked using IsDate()
This then calls a subroutine to change the text box colour and reset the
focus on the text box (all incidentally to speed up entering data into the
form)

HOWEVER.
The second setfocus refused to work! as did the selection process.
when I went back to my first text box and rem out the code of the setfocus
to see if the second set focus would work then nothing happened THEN AFTER
putting the code back to the way it was the FIRST TEXT BOX will not work
either!
Is anyone aware it there is some kind of bug in the software or should I
be
doing something else?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default setfocus

Dean,

I have just run up a simple test and it works okay for me.

Private Sub CommandButton1_Click()
If Len(txtCardNumber.Text) < 1 Then ChangeTextBoxColour
If Not IsDate(txtDate.Text) Then txtDateColour
End Sub

Sub ChangeTextBoxColour()
'change text box colour to show alert
With frmHotlist.txtCardNumber
.BackColor = RGB(255, 0, 0)
.SetFocus
.SelStart = 0
.SelLength = 10
End With

End Sub

Sub txtDateColour()
'change text box colour to show alert
With frmHotlist.txtDate
.BackColor = RGB(255, 0, 0)
.SetFocus
.SelStart = 0
.SelLength = 10
End With

End Sub

What does the rest of your code look like?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dean Reardon" <Dean wrote in message
...
I have a text box which receives a 10 digit number.
A fucntion is then called and the validity of the number is checked.
If the number is invalid the bacground colour of the text box is changed

to
RED and the focus and Selection for the text box is re-set

Sub ChangeTextBoxColour()
'change text box colour to show alert
frmHotlist.txtCardNumber.BackColor = RGB(255, 0, 0)
frmHotlist.txtCardNumber.SetFocus
frmHotlist.txtCardNumber.SelStart = 0
frmHotlist.txtCardNumber.SelLength = 10

End Sub

This initially worked fine until I inserted another text box for the
insertion of a date the validity of the text is checked using IsDate()
This then calls a subroutine to change the text box colour and reset the
focus on the text box (all incidentally to speed up entering data into the
form)

HOWEVER.
The second setfocus refused to work! as did the selection process.
when I went back to my first text box and rem out the code of the setfocus
to see if the second set focus would work then nothing happened THEN AFTER
putting the code back to the way it was the FIRST TEXT BOX will not work
either!
Is anyone aware it there is some kind of bug in the software or should I

be
doing something else?



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
SetFocus on a different sheet in VBA AaronC Excel Discussion (Misc queries) 1 June 9th 05 11:18 PM
setfocus after a msgbox simpleMod[_3_] Excel Programming 1 October 26th 04 07:25 PM
setfocus after a msgbox simpleMod[_2_] Excel Programming 1 October 26th 04 05:25 PM
setfocus after a msgbox simpleMod Excel Programming 1 October 26th 04 04:35 PM
SetFocus Problem Todd Huttenstine[_2_] Excel Programming 2 January 19th 04 10:50 PM


All times are GMT +1. The time now is 03:58 AM.

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

About Us

"It's about Microsoft Excel"