Results 1 to 4 of 4
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Timberville, VA
    Posts
    1,438
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Label format based on checkbox value (Access 2013)

    A table has a Yes/No field to denote whether an item (a record) is "Fragile." On the report based on the table, the checkbox (cbxFragile) Visible property is "No." I've placed a label, "lblFragile," that reads "Fragile!" over top of the checkbox; the label also is normally not visible.

    My intent is that on the report, a record will display Fragile! when "Fragile?" says Yes. I've formatted the Detail section with the following code:

    Private Sub Detail_Format (Cancel As Integer, FormatCount As Integer)
    If IsNull(cbxFragile) Then
    lblFragile.Visible = False
    Else
    lblFragile.Visible = True
    End If
    End Sub

    What happens: On the report, nothing appears in the "Fragile" column for any record, even when there's a checkmark in the Fragile field. I know I've overlooked some small detail, probably in the code. Can someone help me see the error. Thanks!

  2. #2
    2 Star Lounger HiTechCoach's Avatar
    Join Date
    Sep 2011
    Location
    Oklahoma City, OK
    Posts
    162
    Thanks
    0
    Thanked 24 Times in 24 Posts
    I would double check to be sure the CheckBox control named cbxFragile is bound (control source set) to the correct "Fragile" field in hte report's record source.

    One way to test to see if you are getting data in the control cbxFragile is to make it visible. You can set Visible back to false when yu have verified it has the correct values.

    TIP: The "Fragile" field that is a Yes/No data type should never be Null. You you make usere it is always set.


    The coding tip here is the the Check box will have a Yes/No or True/False value. If the Checklbox is true then the Label visible property will also be true. The end result you want can also be seen as the Label visible property will have the same value as the checkbox.


    Here is how I would code this:

    Code:
    Private Sub Detail_Format (Cancel As Integer, FormatCount As Integer)
    
        lblFragile.Visible = Nz(Me.cbxFragile,0)
    
    End Sub
    or

    Code:
    Private Sub Detail_Format (Cancel As Integer, FormatCount As Integer)
    
        lblFragile.Visible = (Nz(Me.cbxFragile,0) = True)
    
    End Sub

    If you want to code in in long hand you could also use:

    Code:
    Private Sub Detail_Format (Cancel As Integer, FormatCount As Integer)
    
        If (Nz(Me.cbxFragile,0) = True) Then
            ' cbxFragile = true
             lblFragile.Visible = True
        Else
           ' cbxFragile = False
             lblFragile.Visible = False
        End If
    
    
    End Sub
    Boyd Trimmell aka HiTechCoach (Access Information here)
    Microsoft MVP - Access Expert
    "If technology doesn't work for people, then it doesn't work."

  3. The Following User Says Thank You to HiTechCoach For This Useful Post:

    Caesar3 (2014-02-13)

  4. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Timberville, VA
    Posts
    1,438
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Boyd, thank you so very much! As you point out, my mistake was thinking of the text box as being "null." I should have been thinking true/false. Thanks for the coding tips!

  5. #4
    2 Star Lounger HiTechCoach's Avatar
    Join Date
    Sep 2011
    Location
    Oklahoma City, OK
    Posts
    162
    Thanks
    0
    Thanked 24 Times in 24 Posts
    You're welcome. Glad we could assist.
    Boyd Trimmell aka HiTechCoach (Access Information here)
    Microsoft MVP - Access Expert
    "If technology doesn't work for people, then it doesn't work."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •