enforce choosing a value in combo-box coding!

  • Thread starter Thread starter Shivalee Gupta via AccessMonster.com
  • Start date Start date
S

Shivalee Gupta via AccessMonster.com

I have a combo-box on a form in access 2000. How can i ensure that whenever
the user does not choose a value from my combo-box, a message is displayed
saying, you have not chosen anything and then nothing is displayed...until
user does'nt chose a value. basically I do not want to see a blank page.
Thanks,
shivalee
 
Thanks to Nikos who has instigated in me the urge to programming.... this
one I tried and did it myself. here is the answer for anyone who needs it...
Onenter in the command button, I wrote:
If IsNull(Combo1) Then
MsgBox "Please select a value", vbDefaultButton1, Error
DoCmd.CancelEvent
Combo1.SetFocus
End If
That was easy!
Its just if anyone can help me in the sense that on that very same form I
have like 10 combo-boxes and for them 10 command buttons. will I have to
write the above code seperately for each? Is there no shorter way out?
Anybody who can help me?
shivalee.
 
Shivalee,

Paste this sub in the form's module:

Sub enforce_no_null(ctl as String)
If IsNull(Me.Controls(ctl)) Then
MsgBox "Please select a value", vbDefaultButton1, Error
DoCmd.CancelEvent
Me.Controls(ctl).SetFocus
End If
end sub

Then paste in eaxh combo's On Enter:

enforce_no_null(Me.ActiveControl.Name)

This should do it.

HTH,
Nikos
 
Thanks nikos.
As always your code worked like a charm.
Thanks a ton.
Shivalee
 
Back
Top