Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Focus Changes to the Wrong Control 2

Status
Not open for further replies.

kopy

Technical User
May 30, 2002
141
US
I'm putting together a quick function to validate the entry of the current control on a form. Everyting is fine, except when I choose the No option in the messagebox, no matter what I seem to do it moves to the next control on the form. I want to stay in the current control and let the user input something else.

Thanks for your help, Kopy.

Here's my code:
===========================================================

Function ValidateEntry()

Dim Msg, Style, Title, Help, Ctxt, Response, MyString

Msg = "Do you really want to input " & Screen.ActiveControl.Value & " ?"
Style = vbYesNo
Title = "Data Entry Validation"

If Screen.ActiveControl.Value >= 35 Then
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
MyString = "Yes"
Else
MyString = "No"
Screen.ActiveControl.Value = 0
Screen.ActiveControl.SetFocus
End If
End If

End Function
 
You cannot set focus to the current control without first setting it to some other control. A better method might be to cancel the event, which can be done if you use the Before Update event.
 
How are ya kopy . . .

Try:
Code:
[blue]   Me(Screen.ActiveControl.Name).SetFocus[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top