Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2009
    Posts
    13

    Unanswered: Check box status defines contents of label

    Hi,

    I've tried to search the forums for check box related threads but I can't pinpoint what I'm looking for.

    This is probably very simple, but as a beginner, I'm struggling to work out how to make a label (or any kind of text box for that matter) display the label titles of check boxes that have been ticked. These labels are derived from field titles in a table.

    Basically, each database entry will have several boxes ticked, but at a glance you can't see them all clearly. For this reason, i'd like a label underneath all the tick boxes that automatically updates with the text label of a check box when you tick it, and removes the text label when you untick it. So in effect, i'll have a summary below of all the tick boxes that have been checked.

    Hope this makes sense!!

    Edit: I'm thinking something along the lines of a macro like this in a memo box...

    Private Sub UPDATED_NOTES_Enter()

    If CHECKBOX1= -1 Then displaytext "CHECKBOX1, "
    If CHECKBOX2= -1 Then displaytext "CHECKBOX2, "
    etc, etc

    End Sub

    It needs to show EVERYTHING that is ticked in one field...be really grateful if someone can point me in the right direction...

    Many thanks,

    Lee
    Last edited by LeeJay; 08-23-10 at 11:40.

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    I would keep an array of strings laying around to store all of the desired checkboxes. Then, create a function/sub that will add or remove a given checkbox name from that array whenever a control is checked. Finally, this same function/sub can be responsible for rifling through the array and building a concatenated string from the values contained therein.

    My VBA is a little rusty, but I can probably mock up some psuedo code or something if that doesn't make sense...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    May 2005
    Posts
    126
    Provided Answers: 1
    Hi

    I think I have understood your request

    When you create your checkbox name it accordingly, e.g. “Tickbox1” , then name the label associated with the checkbox e.g. “LabelForTickBox1”, in the properties of the checkbox select the field “OnClick”, a drop down will appear and next to that … button select tah and select code builder, paste in the code below

    Try this, basically when you tick the check box, the label associated with that checkbox appears, when you uncheck it, it dissapears

    Private Sub TickBox1_Click()

    'Set TickBox1'
    'If True then Label becomes visible, else label is invisible

    If Me.TickBox1 = True Then
    Me.LabelForTickBox1.Visible = True

    End If


    If Me.TickBox1 = False Then
    Me.LabelForTickBox1.Visible = False
    End If


    End Sub
    Last edited by MarkWhyte; 08-23-10 at 12:42.

  4. #4
    Join Date
    Aug 2009
    Posts
    13
    Hi Teddy,

    Thanks for your quick reply, but i'm still quite unsure how to implement your suggestion. I wouldn't know how to even start with keeping an array of strings! I really am a n00b at this stuff and coupled with the fact I haven't touched databases for months hasn't helped!

    I've attached a picture of the database as it stands.

    I'd like all the ticked check box titles to appear in the updated notes memo box automatically if possible. It doesn't have to be a memo box, just something that will store enough text.

    Anything example text you could provide when you get time would be great to start me off.
    Attached Thumbnails Attached Thumbnails database.JPG  

  5. #5
    Join Date
    Aug 2009
    Posts
    13
    Hi Mark,

    That's good work!

    I almost thought your interpretation was a better idea than I originally had for a moment. It wouldn't work though would it because if the tick box didn't have a label, I wouldn't be able to see what it was in the first place to be able to tick it off.

    It's inspired me with an idea to maybe make the label text change colour when the check box is selected though?

    Say, turn it from white to red. Can your text be edited a bit to make that happen?

    Lee

  6. #6
    Join Date
    May 2005
    Posts
    126
    Provided Answers: 1
    LeeJay

    Trythis

    Private Sub TickBox1_Click()

    'Set TickBox1'
    'If True then Label becomes red, else lstandard background

    If Me.TickBox1 = True Then
    Me.LabelForTickBox1.BackColor = 255

    End If

    If Me.TickBox1 = False Then
    Me.LabelForTickBox1.BackColor = 12632256
    End If


    End Sub

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    I have an idea that wouldn't use arrays...

    The idea here is to append or delete the checkbox's name to a target textbox (which I'll call txtCheckedControls) "Text" property:

    Code:
    ' TargetString will be the name of the control we want to add to the existing string.
    ' The AddString boolean tells us if we're appending (true) or removing (false)
    Sub BuildCheckedControlsString(ByVal TargetString As String, ByVal AddString As Boolean)
       If (AddString = true)
          txtCheckedControls.Text = txtCheckedControls.Text + ", " + TargetString
       Else
          ' This is slightly tricky.  We're finding our target text and replacing it with a zero-length string, effectively "deleting" TargetString from txtCheckedControls.Text
          txtCheckedControls.Text = Replace(txtCheckedControls.Text, ", " + TargetString, "")
       End If
    End Sub
    
    Sub SomeCheckBox_Click()
       BuildCheckedControlsString("SomeCheckBox", SomeCheckBox.Checked)
    End Sub
    
    Sub SomeOtherCheckBox_Click()
       BuildCheckedControlsString("SomeOtherCheckBox", SomeOtherCheckBox.Checked)
    End Sub
    
    ... etc
    You could do the label thing by using the Controls collection of your current form:
    Code:
    Sub ChangeLabelText(ByVal TargetLabelName As String, byVal Color As Long)
       Me.Controls(TargetLabelName).BackColor = Color
    End Sub


    *** Note I did not test any of this. It only serves as psuedo code...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  8. #8
    Join Date
    Aug 2009
    Posts
    13
    Hi Guys,

    Thank you both for your suggestions. Teddy, I'm really struggling to get your code to work, i've been tinkering with it for quite a while now, and I don't really know what I'm supposed to do with it.

    But to be honest, I'm preferring this idea of the label text changing colour as you click the check box. It's instant and it's clear to see what you've checked at a glance.

    However, from Mark's code it only works to a degree. It changes the label to either red or white, but only upon each click. For instance, if I click it off so it goes white, when I go to the next record, even if this record has the checkbox checked, it isn't red, it is white. It only changes to red again when I click it off, and then on and then every record is red.

    Obviously, this is because the event only occurs upon a click on the checkbox, but I'd like it so that every record you see constantly has either red or white labels depending on whether the box for that record is checked or not.

    Is that confusing or does it make sense?

    Really appreciate the work here guys, I wouldn't have a clue otherwise!!

  9. #9
    Join Date
    Aug 2009
    Posts
    13
    Hi, Sorry for double posting about this, but does anyone have any ideas about my query? I'm at a bit of a loss!! Thanks!

  10. #10
    Join Date
    Aug 2009
    Posts
    13
    Hi Guys, don't mean to keep going on about this, but does anyone have any ideas? Or is it just not possible?

    Many thanks!

Posting Permissions

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