Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
SetFocus on a different sheet in VBA | Excel Discussion (Misc queries) | |||
setfocus after a msgbox | Excel Programming | |||
setfocus after a msgbox | Excel Programming | |||
setfocus after a msgbox | Excel Programming | |||
SetFocus Problem | Excel Programming |