Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

Trying to force an answer in a combobox

I have this code in the afterupdate event of a combobox.  But the field lets be go on to the next field without forcing an entry in the combobox.

What am I doing wrong?  (it is a text field if that matters)

My code:

    If IsNull(cboDCAORD) Then
        MsgBox "You must select either Accept or Deny in this field."
        Me.cboDCAORD.SetFocus
        Exit Sub
    End If

Open in new window

Avatar of dovidf
dovidf
Flag of United States of America image

You could add or if cboDCAORD = "". However, getting them stuck in that field could be frustrating. An alternative approach that I've used is to set the field red to denote error and not let them get off the page at the end if any fields are marked as not validated.
Avatar of SteveL13

ASKER

I actually want them to get stuck on the field.  I added your suggestion and they get the message but the focus does not stay on the combobox.
SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America 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
ASKER CERTIFIED SOLUTION
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
Dale and Rey...  I've tried both suggestions.  But now if the user decides to delete the record after data has been entered, they get the message even though they don't even want the record any longer.
SOLUTION
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
or simply press the Esc key once  (for the current control) or twice for the entire record.  I generally prefer the cancel button though.