AfterUpdate

G

Guest

I have an Access 97 database. On an unbound form I have serveral text box
controls. On the AfterUpdate event of one text box there is an IF statement.

If a variable returns false, set the focus back to the same control and Exit
Sub.

The Exit Sub works but the set focus is not. Can you use setfocus to the
same control on the contol's afterupdate? If not, is there a way around this?

Thanks
LeAnn
 
R

RuralGuy

LeAnn said:
I have an Access 97 database. On an unbound form I have serveral text
box controls. On the AfterUpdate event of one text box there is an IF
statement.

If a variable returns false, set the focus back to the same control
and Exit Sub.

The Exit Sub works but the set focus is not. Can you use setfocus to
the same control on the contol's afterupdate? If not, is there a way
around this?

Thanks
LeAnn

Hi LeAnn,

Without knowing a little more about your form I'll offer a suggestion:

Can you move all of your AfterUpdate code to the BeforeUpdate event and
then use Cancel = True to keep the focus on this control?

HTH
 
B

Brendan Reynolds

The AfterUpdate event occurs before the control loses the focus, so setting
the focus to the same control in the AfterUpdate event will have no effect.
Try using the Exit event instead, and setting the Cancel argument to True to
prevent focus moving away from the control.
 
V

Van T. Dinh

AfterUpdate is too late. Use the BeforeUpdate Event and if necessary,
set Cancel = True to retain the Focus on the TextBox.
 
G

Guest

Thanks to all for the input. I tried both the BeforeUpdate and the Exit
event. I received the 2115 error on the BeforeUpdate (won't let the data be
saved to the field) so I went with the Exit event which works perferctly!
 
B

Brendan Reynolds

The Exit event is the one to use if you want to allow the data to be changed
but prevent the control from losing focus. The BeforeUpdate event would the
event to choose if you wanted to prevent the control from losing focus and
also prevent the data from being changed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top