Need to make Option Group Required in a Form

G

Guest

I have a form, whose record source is a query. In the underlying table I
have a field called LWC, which is a required field.

On my form, I have an option box with 2 options, essentially a true/false
scenario. which populate the LWC field with either a 1 or a 2. I need to
require that one of these options to be chosen before the user exits the form.

Based on some of the posts here, I have written an Event Procedure in the
"Before Update" Properties of the form as follows:

If IsNull(Me.Option1) AND IsNull(Me.Option2) Then
MsgBox "Please Enter a Mail Group"
Cancel = True
End If

It isn't working - nothing prevents you from closing the form without one of
these options checked. What am I doing wrong? Am I correct that Me.Option1
and Me.Option2 be the names of the option buttons?

Any suggestions are appreciated!
 
D

Douglas J. Steele

When you say you have an option box, I assume you mean you selected Option
Group from the tool box, and added that to your form. If so, then it's the
Option Group you need to check for Null, not the individual controls within
it.
 
J

J. Goddard

You code looks OK - but if a user exits the form without having made any
changes, that event won't occur, so it does not detect the error.

Try using an option box with two radio buttons, which have a value of 1
or 2, and set the default value of the option box to the most common
choice - that way it will always have a value of 1 or 2. Bind the
option box to the LWC field.

Another thing to check - are you sure the source query for the form can
be updated?

Hope this helps

John
 
G

Guest

John,

You're right about exiting without making changes, but all the current
records have an option already chosen, so it's only the new ones that I was
concerned with. Thanks for your help. Everything is working now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top