Solved Using a textbox instead of a checkbox - translating actual values to corresponding Wingdings characters? (1 Viewer)

AOB

Registered User.
Local time
Today, 03:24
Joined
Sep 26, 2012
Messages
615
Came across this thread in the Code Repository as a neat little workaround for displaying checkboxes a little larger and with a touch of colour but struggling with one tiny detail (and the thread is no longer open for replies) if anyone can point me in a direction?

How does one "translate" the value contained the boolean field (i.e. 0 or 1, or I guess potentially -1) into the appropriate character in the Wingdings font library (i.e. þ or ý for ticked-box and crossed-box, respectively?)

I can format the textbox fine but I can only get the Wingdings characters directly corresponding to 0 and 1 (which I think are folder icons) - how do I show zeroes as crosses and non-zeroes as ticks? Do I have to do the conversion in the query that's bound to the form? Would prefer not to do that as I want to retain the true "value" and only present the values aesthetically...

Thanks!
 

AOB

Registered User.
Local time
Today, 03:24
Joined
Sep 26, 2012
Messages
615
Came across this thread in the Code Repository as a neat little workaround for displaying checkboxes a little larger and with a touch of colour but struggling with one tiny detail (and the thread is no longer open for replies) if anyone can point me in a direction?

How does one "translate" the value contained the boolean field (i.e. 0 or 1, or I guess potentially -1) into the appropriate character in the Wingdings font library (i.e. þ or ý for ticked-box and crossed-box, respectively?)

I can format the textbox fine but I can only get the Wingdings characters directly corresponding to 0 and 1 (which I think are folder icons) - how do I show zeroes as crosses and non-zeroes as ticks? Do I have to do the conversion in the query that's bound to the form? Would prefer not to do that as I want to retain the true "value" and only present the values aesthetically...

Thanks!
Aaargh - sorry - just a case of changing the Format string :

\[[Blue]\þ;[Blue]\þ;[Red]\ý
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 03:24
Joined
Jul 9, 2003
Messages
16,282
You might be interested in one of my products. It displays images, one image for the yes and one image for the no.


If you would like a free copy then send me a private message within this forum and I will send you a coupon code.
 
  • Like
Reactions: AOB

AOB

Registered User.
Local time
Today, 03:24
Joined
Sep 26, 2012
Messages
615
You might be interested in one of my products. It displays images, one image for the yes and one image for the no.


If you would like a free copy then send me a private message within this forum and I will send you a coupon code.
Thanks Uncle Gizmo, unfortunately firewalls prevent me from downloading "third party" software but I do appreciate the offer! I have used a command-button-in-place-of-a-checkbox myself elsewhere and it works really nicely, it just doesn't work very well as a field in a continuous subform, hence the Wingdings solution as an alternative. Probably not as fancy as yours but in this particular case it doesn't need to be.
 

baderms

New member
Local time
Yesterday, 22:24
Joined
Feb 14, 2023
Messages
8
I don't remember where I got this from but try this

Code:
I've set the Font property to WingDings font because it actually contains a checkmark. I'm going to set the caption of the lblUnboundCheckbox to that character when I want a checkmark and to a zero-length string ("") when I don't. The final step is to adjust the height and width of the label so that the checkmark is fully displayed.

Now, checkboxes toggle from checked to unchecked when you click on them. Fortunately, labels have a Click event, so I use code to control the appearance of my simulated checkbox:

Private Sub lblBadExhibits_Click()

 If IsNull(chkBadExhibits) Then
    chkBadExhibits = True
  Else
    chkBadExhibits = Not chkBadExhibits
  End If

  If chkBadExhibits = True Then
    lblBadExhibits.Caption = Chr(252)
  Else
    lblBadExhibits.Caption = Chr(32)
  End If

End Sub

When the large checkbox is clicked on, I toggle the hidden checkbox (if it was checked, it becomes unchecked, and vice versa). I then base what I display in my simulated checkbox on the value of that checkbox.

If the hidden checkbox is bound to a field in the form's recordset, I can simulate binding the large checkbox to the data field by using code in the form's Current event:

Private Sub Form_Current()

  If chkBadExhibits = True Then
    lblBadExhibits.Caption = Chr(252)
  Else
    lblBadExhibits.Caption = Chr(32)
  End If
 
End Sub

If you want a CheckBox field label, just add another unbound label and set its caption to the CheckBox's field name (and leave it Visible).

Unfortunately, this approach doesn't work for continuous forms. This is because, in a continuous form, Access has just one set of control properties for each control for all the records displayed. So, when you change the caption on a label, you change the caption for that label on every record. To get around this, you can use a text box instead and use the text box's ControlSource property to manage whether the check appears. The ControlSource for a text box is the one property that won't be replicated across all the records in the continuous form.

Begin by adding a text box to your continuous form and set the properties as shown in Table 2.




I bind my hidden checkbox to a field in the form's recordset. For the text box, I can set its ControlSource property to a formula that uses the IIF function. If, for example, the field in the recordset that I want to bind to is named Discontinued, I set the text box's control source to:

=IIf([Discontinued], Chr$(252), Chr$(32))

You still need code to ensure that the underlying recordset field is updated to reflect changes in the checkbox's status. Again, I use the text box's Click event for this:

Private Sub txtBoundCheckBox_Click()

  Me.Discontinued = Not Me.Discontinued

End Sub

Since the control is bound to the data, there's no need for code in the form's Current event to update the field in the record.
 
  • Like
Reactions: AOB

AOB

Registered User.
Local time
Today, 03:24
Joined
Sep 26, 2012
Messages
615
I don't remember where I got this from but try this

Code:
I've set the Font property to WingDings font because it actually contains a checkmark. I'm going to set the caption of the lblUnboundCheckbox to that character when I want a checkmark and to a zero-length string ("") when I don't. The final step is to adjust the height and width of the label so that the checkmark is fully displayed.

Now, checkboxes toggle from checked to unchecked when you click on them. Fortunately, labels have a Click event, so I use code to control the appearance of my simulated checkbox:

Private Sub lblBadExhibits_Click()

If IsNull(chkBadExhibits) Then
    chkBadExhibits = True
  Else
    chkBadExhibits = Not chkBadExhibits
  End If

  If chkBadExhibits = True Then
    lblBadExhibits.Caption = Chr(252)
  Else
    lblBadExhibits.Caption = Chr(32)
  End If

End Sub

When the large checkbox is clicked on, I toggle the hidden checkbox (if it was checked, it becomes unchecked, and vice versa). I then base what I display in my simulated checkbox on the value of that checkbox.

If the hidden checkbox is bound to a field in the form's recordset, I can simulate binding the large checkbox to the data field by using code in the form's Current event:

Private Sub Form_Current()

  If chkBadExhibits = True Then
    lblBadExhibits.Caption = Chr(252)
  Else
    lblBadExhibits.Caption = Chr(32)
  End If

End Sub

If you want a CheckBox field label, just add another unbound label and set its caption to the CheckBox's field name (and leave it Visible).

Unfortunately, this approach doesn't work for continuous forms. This is because, in a continuous form, Access has just one set of control properties for each control for all the records displayed. So, when you change the caption on a label, you change the caption for that label on every record. To get around this, you can use a text box instead and use the text box's ControlSource property to manage whether the check appears. The ControlSource for a text box is the one property that won't be replicated across all the records in the continuous form.

Begin by adding a text box to your continuous form and set the properties as shown in Table 2.




I bind my hidden checkbox to a field in the form's recordset. For the text box, I can set its ControlSource property to a formula that uses the IIF function. If, for example, the field in the recordset that I want to bind to is named Discontinued, I set the text box's control source to:

=IIf([Discontinued], Chr$(252), Chr$(32))

You still need code to ensure that the underlying recordset field is updated to reflect changes in the checkbox's status. Again, I use the text box's Click event for this:

Private Sub txtBoundCheckBox_Click()

  Me.Discontinued = Not Me.Discontinued

End Sub

Since the control is bound to the data, there's no need for code in the form's Current event to update the field in the record.

Nice - I didn't realise you could use a formula in the ControlSource property of a control in a continuous subform. Might use that somewhere else... Ultimately, though, this will result in the same behaviour as formatting the control for positive;negative;zero;empty values (replacing the zero or non-zero with an arbitrary character from the ASCII set, and using the font to display that character as a symbol) And the format option gives the additional flourish of changing the colour between values.
 

Users who are viewing this thread

Top Bottom