Thread: setfocus
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
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?