Require value in option group (1 Viewer)

rhonda6373

Registered User.
Local time
Today, 11:51
Joined
Jun 14, 2015
Messages
22
I have an option group (optResponse31) that has 3 buttons. I want a message to pop up when the user clicks on the form by clicking the X on the top right of the form. I want the message to state "Please enter a value." if no value is entered.

I tried to set the required property in the table to Yes and that did not work. I also tried the following code. The code makes the message pop up if a value is entered or not and when you click OK on the message it closes the form anyway.

What am I doing wrong? Thanks!

Code:
Private Sub Form_Close()
'check for required fields
If IsNull(Me.optResponse31) = True Then
    MsgBox "Please enter a response."
    Me.optResponse31.SetFocus
Else
   'Close the form.
    DoCmd.Close
End If
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 11:51
Joined
Oct 29, 2018
Messages
21,622
Hi. It would be nice to know your actual workflow, so we can give you a more appropriate approach but you could try using the form's Unload event for starters. For example:
Code:
If IsNull(Me.optResponse31) Then
    MsgBox "Please enter a response.", vbInformation, "Info"
    Cancel=True
End If
 

rhonda6373

Registered User.
Local time
Today, 11:51
Joined
Jun 14, 2015
Messages
22
Thanks DBguy. That will work for this purpose.
 

Minty

AWF VIP
Local time
Today, 19:51
Joined
Jul 26, 2013
Messages
10,387
If you set a default value for the option group I am pretty sure you can't then deselect it, meaning that it's impossible to not have a value.

Not sure if that helps you?
 

Users who are viewing this thread

Top Bottom