Link to home
Start Free TrialLog in
Avatar of pauldownham
pauldownham

asked on

How to force a field not to be left blank

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.
ASKER CERTIFIED SOLUTION
Avatar of MikeToole
MikeToole
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Maybe you can use
IsNull([newlabel]) or IsEmpty([newlabel])
Avatar of pauldownham
pauldownham

ASKER

works a treat ... thanks!