setFocus back to incorrect entry

solotoo

Registered User.
Local time
Today, 11:10
Joined
Nov 16, 2004
Messages
14
Help please

I have created a form in Excel with text entry boxes, in the first box the text required is either A,B or C.
If an incorrect letter is entered I want to focus to go back to this cell. But I can t seem to manage this.

The code I have is...

Private Sub txt_ABC_Exit(ByVal Cancel As MSForms.ReturnBoolean)

txt_ABC.Text = UCase(txt_display.Text)

If txt_ABC.Text Like "[A,B,C]" <> False Then
txt_NEXT.SetFocus
Else
txt_ABC.SetFocus
lbl_error.Caption = "Error, incorrect entry"
'txt_ABC.SelStart = 0 ' tried this - didnt work!!
End If
End Sub


I can get focus on any other text box but the one I want!
Any ideas greatfully received.
 
Thanks

I'll try that, unfortunately I can't use combo boxes as Im trying to emulate an existing screen which has been written in MSBASIC/DOS6 or something as ancient!! :eek:
 
solotoo said:
Help please

I have created a form in Excel ....

Also in the wrong forum :eek:


.
 
Oldsoftboss said:
Also in the wrong forum :eek:
.

I thought as this was a VBA question it should go in the VBA thread, not the specific Excel Thread.
 
solotoo said:
Help please

I have created a form in Excel with text entry boxes, in the first box the text required is either A,B or C.
If an incorrect letter is entered I want to focus to go back to this cell. But I can t seem to manage this.

The code I have is...

Private Sub txt_ABC_Exit(ByVal Cancel As MSForms.ReturnBoolean)

txt_ABC.Text = UCase(txt_display.Text)

If txt_ABC.Text Like "[A,B,C]" <> False Then
txt_NEXT.SetFocus
Else
txt_ABC.SetFocus
lbl_error.Caption = "Error, incorrect entry"
'txt_ABC.SelStart = 0 ' tried this - didnt work!!
End If
End Sub


I can get focus on any other text box but the one I want!
Any ideas greatfully received.

The proper event to use would be the Worksheet_Change() for that Excel worksheet. But I do not recommend that method.

The easiest way to restrict what the users enters would be to use "Validation" for the needed cells. Select the cells you want to validate and click the menu bar options in Excel; Data / Validation... and choose these settings... Allow: = List, Source: = A,B,C, Check the "In-Cell Dropdown" option in the Settins tab. Customize your message in the Input Message and Error Alert tabs. Play around with the settings until you get the desired resilts.
 

Users who are viewing this thread

Back
Top Bottom