Cursor placement

barboza

Registered User.
Local time
Today, 18:52
Joined
Aug 22, 2007
Messages
23
Hello All,


If the user enters an invalid client name in the client field of a form, I have a msgbox pop up that says invalid client name. No problem. I want to make the cursor go back to the client filed in the form to correct the entry.

What is the vba code that will allow me to place the cursor in the client field? I do not want to use sendkeys "{UP}" as the form will be changed in the near future.

I've tried stuff like: me.Client.SetFocus, and .GotFocus.

No matter what I do, the cursor is always one field past where I want it after the invalid client name msgbox pops up.

Any help would be greatly appreciated!!!

Thanks in advance,

Barboza
 
Use the BeforeUpdate event of the control in conjunction with Cancel=True
 
If you do as Rich suggests and use the control's Before Update event you can validate the value entered and if it isn't correct you can simply use

Cancel = True

To cancel the update of the control. Now to address the problem you are having as to setting focus, you need to make sure that you are using the actual control name (not necessarily field name) when doing so. It is totally possible that your control is named something like Text12 instead of Client and so trying to set focus to the field, instead of the control, will not work.

You can set the focus to a control by using:

Me.YourControlNameHere.SetFocus
 

Users who are viewing this thread

Back
Top Bottom