D
Don
I have a fairly simple userform with a frame and two
textboxes inside the frame. If a user makes an invalid
entry I want to display a message, clear the entry, and
set the focus back to the same field.
The mesgbox displays perfectly, and the entry is cleared
fine. However, the focus keeps going to the next textbox
in the frame. I am getting frustrated! I even tried
setting the focus back to the frame first, and then to the
field. I also tried using the Exit event with no success.
I am using the AfterUpdate event and the name of my
textbox is txtClientNumber. My code appears below.
Any ideas would be apprecaited. Thanks so much in advance.
Private Sub txtClientNumber_AfterUpdate()
Dim StrClientName As String
Dim rstClientName As ADODB.Recordset
Set rstClientName = New ADODB.Recordset
StrClientName = "SELECT client_name FROM hbm_client
WHERE client_code = '" & txtClientNumber.Value & "'"
rstClientName.Open StrClientName, Main.cnn
If rstClientName.EOF = True Then
MsgBox "That is an Invalid Client Number"
txtClientNumber.Value = Null
frmMain.fme1.SetFocus
txtClientNumber.SetFocus '***PROBLEM HERE
Else
rstClientName.MoveFirst
txtClientName.Value = rstClientName
("client_name").Value
End If
End Sub
textboxes inside the frame. If a user makes an invalid
entry I want to display a message, clear the entry, and
set the focus back to the same field.
The mesgbox displays perfectly, and the entry is cleared
fine. However, the focus keeps going to the next textbox
in the frame. I am getting frustrated! I even tried
setting the focus back to the frame first, and then to the
field. I also tried using the Exit event with no success.
I am using the AfterUpdate event and the name of my
textbox is txtClientNumber. My code appears below.
Any ideas would be apprecaited. Thanks so much in advance.
Private Sub txtClientNumber_AfterUpdate()
Dim StrClientName As String
Dim rstClientName As ADODB.Recordset
Set rstClientName = New ADODB.Recordset
StrClientName = "SELECT client_name FROM hbm_client
WHERE client_code = '" & txtClientNumber.Value & "'"
rstClientName.Open StrClientName, Main.cnn
If rstClientName.EOF = True Then
MsgBox "That is an Invalid Client Number"
txtClientNumber.Value = Null
frmMain.fme1.SetFocus
txtClientNumber.SetFocus '***PROBLEM HERE
Else
rstClientName.MoveFirst
txtClientName.Value = rstClientName
("client_name").Value
End If
End Sub