Make field on a form manitory and return user to that field before anything else can be entered if they skip it

I have a form with a combo-box.  That field is tab 0 on the form so the focus is on it when the form opens.  But if the user skips over the field and attempts to enter any other data in any other field before the combo-box has had a record selected I want the data they entered in any other field deleted, have a message box appear letting the user know they have to select a record in the combo-box before proceeding, and return the focus to the combo-box.

How do this?
SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteveL13Author Commented:
So I have this code in the lostfocus event of the combobox field but it is not taking the user back to the combobox field.  Instead it is setting the focus on the next field.  ????

Private Sub cboSalesperson_LostFocus()

    If IsNull(Me.cboSalesperson) Then
        MsgBox "You must select a salesperson before proceeding!"
        Me.cboSalesperson.SetFocus
        Exit Sub
    End If

End Sub

Open in new window

0
PatHartmanCommented:
Are you trying to select a record for a particular salesperson or are you creating a new record (or changing an existing one) and salesperson is simply a piece of data?  If the former, the Salesperson combo will not be bound and it will have code in it that goes to a specific, EXISTING record.  In this situation, you could use the Form's BeforeInsert event to trigger the error because since you are only updating existing records, the BeforeInsert event should never be triggered.  If it is the latter, what difference does it make (to quote a certain presidential candidate)?  Unless you are using the combo to hide/show other controls, why does it matter if the user enters it first or last?  If the field is required, you would validate its presence in the Form's BeforeUpdate event.  That is the only event you can consistently use to ensure that specific controls have data.  Control level events do not work because if the control never got the focus, no control level event would fire.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
It is the latter and I'll use the BeforeUpdate event.  Thanks.
0
PatHartmanCommented:
The Form's BeforeUpdate event is without question, the most important and useful event when it comes to keeping your data accurate.
0
SteveL13Author Commented:
Thanks again.  Is much appreciated.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.