B
bigomega73
I have VBA code which is run in the AfterUpdate event for a text box. It
basically checks to see if the data entered in the text box matches a
criteria. If not, it displays an message box asking if they want to continue.
If not, I want the text box to be re-selected so that they can change the
value. The following is my VBA, which uses SetFocus to re-select the text
box. But for some reason, if I try to SetFocus back on the text box, it is
completely ignored and the form moves on to the next field. However, if I
SetFocus on a different control it will do it just fine. So, I tried to
SetFocus on a different control and then back to the original text box, which
works, but instead of selecting the whole field so that the user can just
re-type their data, the cursor moves to the end of the data so that they user
first has to delete the previous data before re-entering the new data. If I
SetFocus on any other text box, the whole data field is selected like I want.
AARRRRGHHH!!! This is driving me crazy and I have not idea how to work around
this. Can someone please help?
Here's my VBA:
Private Sub TextBox1_AfterUpdate()
Dim TextBoxData As String, Response As Integer
TextBoxData = Me!TextBox1
If TextBoxData <> "Correct Field Data" Then
Response = MsgBox("That is not Correct Field Data. Do you want to
continue?", vbYesNo, "Incorrect Field Data")
If Response = vbNo Then
Me!TextBox1.SetFocus
End If
End If
End Sub
basically checks to see if the data entered in the text box matches a
criteria. If not, it displays an message box asking if they want to continue.
If not, I want the text box to be re-selected so that they can change the
value. The following is my VBA, which uses SetFocus to re-select the text
box. But for some reason, if I try to SetFocus back on the text box, it is
completely ignored and the form moves on to the next field. However, if I
SetFocus on a different control it will do it just fine. So, I tried to
SetFocus on a different control and then back to the original text box, which
works, but instead of selecting the whole field so that the user can just
re-type their data, the cursor moves to the end of the data so that they user
first has to delete the previous data before re-entering the new data. If I
SetFocus on any other text box, the whole data field is selected like I want.
AARRRRGHHH!!! This is driving me crazy and I have not idea how to work around
this. Can someone please help?
Here's my VBA:
Private Sub TextBox1_AfterUpdate()
Dim TextBoxData As String, Response As Integer
TextBoxData = Me!TextBox1
If TextBoxData <> "Correct Field Data" Then
Response = MsgBox("That is not Correct Field Data. Do you want to
continue?", vbYesNo, "Incorrect Field Data")
If Response = vbNo Then
Me!TextBox1.SetFocus
End If
End If
End Sub