Since Setfocus wont work on LostFocus event how can I make completion of two fields compulsory on a form

I have a form where users enter details about a job that needs to be done. In some cases there is a charge (ChargeAmount field) and if they enter a charge amount they need to enter ChargeDetails field too. It's not happening so I tried setting the On LostFocus event to check
IF IsNull(ChargeDetails) and Not IsNull(ChargeAmount) THEN
    MsgBox "You must enter a text",,"Text Required"  
    me.ChargeDetails.setfocus,
ENDIF

The message appears but the focus does not return to the field. Is there any other way of forcing this?
Rob4077Asked:
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.

Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
I've always found it the easiest (And by far the most reliable) to run validation in the FORMS beforeupdate event. This event runs right before the record as a whole, is committed to disk.

Private Sub Form_BeforeUpdate(Cancel as Integer)
IF IsNull(ChargeDetails) and Not IsNull(ChargeAmount) THEN 
    MsgBox "You must enter a text",,"Text Required"   
    Cancel=True 'This line stops the commit to disk.
END IF
End Sub

Open in new window

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
Rob4077Author Commented:
Yep, that will do it. Forgot about the Form Update events. Thanks
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
Windows OS

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.