Share via

Custom Checkbox

Anonymous
2023-02-22T15:30:43+00:00

Since it is not possible to increase the size of Access checkbox, I am trying to create a larger one using Toggle button bound to Yes/No field OnCall. This works fine on existing records using this code:

Private Sub Form_Current()   

    ChkOncall_AfterUpdate

End Sub

Private Sub ChkOnCall_AfterUpdate()

    If OnCall Then

        ChkOnCall.Caption = "✓"

    Else

        ChkOnCall.Caption = ""

    End If

End Sub

But am getting "Invalid use of Null" on a new record. I understand this is because the value of Yes/No field on a new record is Null which changes when something is entered in any field. Is there a way of changing the initial value to No? I have tried this code in Sub Form_Current before calling ChkOncall_AfterUpdate:

If OnCall = Null then

OnCall.value=0

end if

but does not work - on hovering over If OnCall it does show Null but for some reason ignores the next line.

Would appreciate your help in correcting this.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
2023-02-22T16:11:00+00:00

> If OnCall = Null then

This is SQL syntax, but you are in VBA. Change to:

If IsNull(OnCall) then

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Anonymous
    2023-02-23T10:40:57+00:00

    I set the default to False and then 0 but I still get the same error.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-02-22T17:41:39+00:00

    You might like to take a look at BigCheck.zip in my public databases folder at:

    https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169

    If you have trouble downloading a specific file, clicking on the 'Download' button at the top of the page while no files are selected should download a zip file of all files in the folder, from which you should then be able to unpack the relevant file.

    This little demo file stores the TRUE and FALSE values in a conventional Boolean (Yes/No) column in the table.  In the form a text box using the WingDings font simulates a check box.  When the user clicks the control they are actually clicking a transparent button which toggles the value of a hidden check box bound to the Boolean column with:

        Me.chkMyBooleanField = Not Me.chkMyBooleanField

    The dummy check box simulated by a text box has the following as its ControlSource property:

        =IIf([chkMyBooleanField],Chr(252),"")

    252 is the ASCII value for the tick character in the WingDings font.

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,830 Reputation points Volunteer Moderator
    2023-02-22T16:31:46+00:00

    Why not set the Default value on the Table level to False. That should prevent the field from ever being Null.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2023-02-22T15:38:26+00:00

    How about change 'If OnCall Then' to

    'If nz(OnCall, False) Then'

    Was this answer helpful?

    0 comments No comments