Search code examples
ms-accessms-access-2007

Change the value of the Checkbox


I add a new line of data into the table through the form. On the form I also have checkbox which is also integrated into the table. Ticking the checkbox leads to getting a value of -1. Is it possible to change -1 into a user defined value such as 'x'?


Solution

  • Simple answer: No.

    More complex answer: You can use a hidden bound field, an unbound checkbox, VBA and default values to make a checkbox that behaves just like a bound checkbox that returns a different value.

    Consider two fields, myUnboundCheckbox and myBoundTextfield. myBoundTextfield holds "X" for True, "Y" for False. myUnboundCheckbox is an unbound checkbox, myBoundTextfield is a hidden bound text field

    Then you can use the following:

    Private Sub myUnboundCheckbox_AfterUpdate()
        If myUnboundCheckbox Then
            myBoundTextfield = "X"
        Else
            myBoundTextfield = "Y"
        End If
    End Sub
    
    Private Sub Form_Current()
        myUnboundCheckbox = myBoundTextfield = "X"
    End Sub