OK Jim, are you sitting comfortably? Then I’ll begin. (Quote: BBC Radio, ‘Listen With Mother,’ cica 1950)
Consider:
Code:
Private Sub cmdSave_LostFocus()
'Sends focus back to beginning if using Tab key
Me.txtXacnEmpName.SetFocus
End Sub
I guess when you wrote this you believed that only a Tab action could move the focus away from cmdSave and did not realize that VBA’s SetFocus can do exactly the same thing. So, if a validation fails, you are attempting to move the focus to the offending control, away from cmdSave. This procedure is triggered and overrides the validation’s SetFocus action. This is why the focus always returns to the first – txtXacnEmpName – control. (I haven’t dug deep enough to explain why you get the error message but I’m confident it’s all connected.)
So what to do? I understand why you wrote this procedure but it is not the best way to get the tabbing to move circularly around this record only.
- First and foremost, select the form in design view and on the property sheet page go to the ‘Other’ tab. The fourth entry is ‘Cycle.’ Change the selection to ‘Current Record’ and tabbing will go round and round the current record ad infinitum. Now you may delete the cmdSave_LostFocus() procedure.
- If you don’t want the three command buttons to be included in this circular tabbing, select them and go to the ‘Other’ tab on the property sheet. Set ‘Tab Stop’ to ‘No.’ Now your user must click on a command button; (s)he cannot tab to it.
- If you wish to provide a keyboard route to the command button then in the caption property include an ampersand before your chosen shortcut character. For example ‘&Save’ is shown as ‘Save’ and the command button may be invoked by [Alt+S]. At the moment you are displaying bit maps on your buttons so a caption will not show unless you change the picture caption arrangement and button size (or modify your bitmap).
- Another way of providing keyboard routes to command buttons is through the specification of a default button – activated by [Enter] – and a cancel button – activated by [Esc]. Both of these properties are found on the 'Other' tab.
I believe all should work for you now. Uncomment the SetFocus actions and delete or comment out the On Error statements.