Advertisement

02.12.2008 at 05:16AM PST, ID: 23155996
[x]
Attachment Details

How to force a field not to be left blank

Asked by pauldownham in Access Coding/Macros

Tags: microsoft, access, 2002, vba

I have a form that requires an unbound field not to be null, but the data it contains doesn't have to be there in the first place, ie. I can't just make the data a required field in its table.

So I wrote a little bit of VBA to do it ...

Private Sub newlabel_LostFocus()
If IsNull([newlabel]) Then
MsgBox("Content Required")
Me!newlabel.SetFocus
End If
End Sub

This works OK, in that the message pops up under the right conditions (eg. if the user deletes existing content, or leaves a blank entry blank), but the focus moves on to the next field for some reason. I can correct this by adding a SendKeys backtab, but I don't like to use SendKeys and can't see what's wrong with the code.Start Free Trial
[+][-]02.12.2008 at 05:36AM PST, ID: 20874530

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Access Coding/Macros
Tags: microsoft, access, 2002, vba
Sign Up Now!
Solution Provided By: MikeToole
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.12.2008 at 05:44AM PST, ID: 20874596

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628