General discussion

Locked

Access 2000 VBA

By gemailhiot ·
On a previous question, since resolved, I asked about selecting records from a table to validate a pay period.
After implementing the suggested solution, I created a message box that would alert the user that the pay period was not valid and asking him/her whether they wanted to continue (a Yes/No button).
If the user selects not to continue, I would like to return control to the date field instead of the next field in the tab order.
I have tried DoCmd.GoToControl, SetFocus methods.
Focus returns to the right field but does not stay there, instead it leaps directly to the next control in the tab order.
I would like focus to remain with the date field so it may be corrected.

Any suggestion?

Thanks

gilles mailhiot

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Access 2000 VBA

by Crowmoor In reply to Access 2000 VBA

Hi!

Not sure about my solution but it sounds like this is your problem.

You have field with a date.When you leave it you run code to validate it. If its invalid the code puts focus back on the field and when ode has stoppen running the focus then jumps to your next field in taborder.

You problem is that you misscalculated your eventtiming. When you press tab to leave the field the code runs and after running Access does the tab-movement.

Simple quickfix is to put a boolean in your code an set it to true if focus should remain on your control. Then check for the boolean at GotFocus event in you next control and put focus back.

A better solutions is to rethink where you put your validationcode. Check DoCmd.CancelEvent in yourhelp for a good advice and example.

Got other problems with Access or VBA please feel free to mail me. Have developed in Access since Access 2.0.

jesper.krakhede@g2solutions.se

Jesper

Collapse -

Access 2000 VBA

by gemailhiot In reply to Access 2000 VBA

Thanks for all the help, Jesper

Gilles Mailhiot

Collapse -

Access 2000 VBA

by SanKulPune In reply to Access 2000 VBA

Hello,

Put all your validation code in the 'exit' event of the date field.

Replace the statement
<datefield>.SetFocus

with

Cancel = True

and run the form.


If you can send me a copy of the code you are using, I will send back you the modified code.

Your feedback will be highly appreciated.

with regards,

SanganakSakha,
Simple And Effective Solutions To Small Problems, No QuickFixes.

Collapse -

Access 2000 VBA

by gemailhiot In reply to Access 2000 VBA

Poster rated this answer

Collapse -

Access 2000 VBA

by donq In reply to Access 2000 VBA

When VB code ends control is returned to the Previous Control by default. At the very beginning of your procedure enter the line "<DateFieldName>.SetFocus" and focus will return where you want it instead of the button that executed the code.

Collapse -

Access 2000 VBA

by gemailhiot In reply to Access 2000 VBA

Poster rated this answer

Collapse -

Access 2000 VBA

by gemailhiot In reply to Access 2000 VBA

This question was closed by the author

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums