Set the Focus back to the Texbox

usermj

Registered User.
Local time
Today, 09:06
Joined
Dec 12, 2004
Messages
39
Referring to the previous post 'Textbox Validation' issue, I met a problem on set the focus back to the TextBox.

I used the 'OnLostFocus()' event on the Textbox to validate the entry. After that, I want to set the focus back the Textbox, which allows the user to correct their entry. But the TextBox.SetFocus() doesn't help me so.




Is there sth wrong with my code or not?

Thanks
 
You can use:

Me!Textbox1.Setfocus

In your code,

Regards,
 
The trick is to set focus to another control first, then "back to" this control, since you're using such event.

If you're going the path of control validation, in stead of using the forms before update event, I'd recommend taking a look at the controls before update event, which can be cancelled thru; cancel = true (effectively denying change of focus if it doesn't validate).
 
Pat Hartman said:
Use the BeforeUpdate event for your editing. That way the edit only happens if the field is dirty and you don't have to worry about where the focus is. You just cancel the update event and focus remains in the field until the field is correct or the user cancels the update.
Code:
If some condition is an error Then
    Cancel = True
    MsgBox "some error message", vbOKonly
End If

Thanks :)

Quote From MSDN.microsoft:
=======================
The BeforeUpdate event occurs before changed data in a control or record is updated.

Private Sub object_BeforeUpdate(Cancel As Integer)

Object The name of a form or a control.

Cancel The setting determines if the BeforeUpdate event occurs. Setting the Cancel argument to True (–1) cancels the BeforeUpdate event.

================

One more thing:

It did help me keep the focus in the original Textbox. Is there any chance I can hightlight that Textbox??? like: using blue color to highlight that value?

Many thanks :)
 
Thanks for your reply.

I just notice (Me.TextBox.Undo) function can help me highlight the whole TextBox.


P.S.
I just came across a DLookup() function. It can also be used to validate the entry value , which is based on the existing data in the Table.

Hope this can give some help to whoever is interested on it.
 

Users who are viewing this thread

Back
Top Bottom