Ask Your Question
1

Getting only one of two check boxes marked

asked 2017-11-14 13:41:50 +0200

loved.by.Jesus gravatar image

updated 2017-11-20 12:45:36 +0200

Hello,

I am designing a form and I use check boxes for the user to mark 'yes' or 'no'. The problem is that eventually one can check the two check boxes, which make no sense "[x] Yes [x] No". I would like that only one of both can be checked. For example, if the 'Yes' is checked and the user checks the 'No', the 'Yes' should be unchecked and vice versa.

Thanks!

edit retag flag offensive close merge delete

Comments

1

Use Option button for that, not Check box

Mike Kaganski gravatar imageMike Kaganski ( 2017-11-14 14:03:14 +0200 )edit

Thanks that was a quite first answer. Though it does not look like I wanted.

loved.by.Jesus gravatar imageloved.by.Jesus ( 2017-11-14 14:49:13 +0200 )edit

Is this for Calc, Writer or Base? Please use one of those tags instead of "common" so that we know what kind of form this is asking about. (That is why I could not give an example macro in my answer.)

Jim K gravatar imageJim K ( 2017-11-14 17:15:09 +0200 )edit

@Jim K: yes it is for Libreoffice Writer (I did retag the question) If you can add the macro in your answer it would be great!

loved.by.Jesus gravatar imageloved.by.Jesus ( 2017-11-20 12:43:50 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2017-11-14 17:09:19 +0200

Jim K gravatar image

updated 2017-11-20 19:44:33 +0200

As @Mike Kaganski said, use option buttons.

If only one choice is allowed, then the button should look like (o) because this is the standard. Otherwise, if it looks like [x] then people will think it is possible to check both.

If you still decide to use check boxes, then write a macro to uncheck the other box.

EDIT:

Right-click on a check box in Design View and select Control. For the code below, set the Name properties to chkYes and chkNo. In the Events tab, use the following macro for the Execute action of both.

Sub MutuallyExclusiveCheckboxes(event As ActionEvent)
    model = event.Source.Model
    form = model.getParent()
    If model.Name = "chkYes" Then
        otherName = "chkNo"
    Else
        otherName = "chkYes"
    End If
    otherControl = form.getByName(otherName)
    otherControl.State = False
End Sub
edit flag offensive delete link more

Comments

I truly do not like the round buttons, therefore If you have some quick macro-code for the check-boxes, it would be great. Thanks

loved.by.Jesus gravatar imageloved.by.Jesus ( 2017-11-20 12:46:48 +0200 )edit

See edited answer.

Jim K gravatar imageJim K ( 2017-11-20 19:44:43 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-11-14 13:41:50 +0200

Seen: 78 times

Last updated: Nov 20 '17