• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Access: How to automatically populate a text field in a form based on whether checkboxes are clicked?

bubbasmith99

Senior member
I am working on a customer service database. There are four different customer service call types that appear as checkboxes. After taking in a call, a CSR can check off just one or they can check off all 4.

These check boxes are a complete pain in the backside when I attempt to run queries on the different types of customer service call types. So I want to create a field in the table that will automatically generate the call type(s) based on whether or not the corresponding checkboxes have been checked off.

So, for instance, if

Blue [x]
Red [ ]
Green [ ]
White [ ]

then the hidden field would just read "blue"

if

Blue [x]
Red [ ]
Green [x]
White [ ]

then the hidden field would read "blue green"

if

Blue [x]
Red [x]
Green [x]
White [x]

then the hidden field would read "blue red green white"

Does anybody have any idea how i would go about doing this? Thanks for your help.
 
Setup a handler for each checkbox that calls the same funciton.

The function would look at the check state of each box and generate a string based on the state of the check box. this string when all checkboxes are processed, should then fill in the hidden field
 
I would do it through an onsubmit handler on the form. I threw together the following code that will set a hidden field to the right value when the form is submitted. Sorry, I'm being a bit lazy and ony got this working for IE. Mozilla doesn't seem to want to run the "set_hidden_field" function correctly.

<html>
<head>
<script>
function set_hidden_field()
{
if (form.bluecheckbox.checked)
{
form.hiddenfield.value += "blue ";
}
if (form.redcheckbox.checked)
{
form.hiddenfield.value += "red ";
}
if (form.greencheckbox.checked)
{
form.hiddenfield.value += "green ";
}
if (form.whitecheckbox.checked)
{
form.hiddenfield.value += "white ";
}
// remove the last space in the hidden value
form.hiddenfield.value = form.hiddenfield.value.substring(0,form.hiddenfield.value.length-1);
}
</script>
</head>
<body>
<form id="form" name="form" method="get" onsubmit="javascript:set_hidden_field()">
<input type="checkbox" name="bluecheckbox" id="bluecheckbox">blue</input><br />
<input type="checkbox" name="redcheckbox" id="redcheckbox">red</input><br />
<input type="checkbox" name="greencheckbox" id="greencheckbox">green</input><br />
<input type="checkbox" name="whitecheckbox" id="whitecheckbox">white</input><br />
<input type="hidden" name="hiddenfield" id="hiddenfield" />
<input type="submit" />
</form>
</body>
</html>
 
I am assuming your using VBA. So you would need 4 unbound checkboxes and a text box bound to the field in the table. Then try this code on the before update event.

Dim strTest As String
If Me.Check0 = "-1" Then
strTest = strTest & "Blue "
End If

If Me.Check2 = "-1" Then
strTest = strTest & "Green "
End If

If Me.Check4 = "-1" Then
strTest = strTest & "Red "
End If

If Me.Check6 = "-1" Then
strTest = strTest & "Yellow "
End If

Me.Text8 = Null

If Not strTest = "" Then
Me.Text8 = strTest
End If

That should give you what yu want.

Vegas😎
 
thanks vegas. i'll try that out on monday

i appreciate your help oog but i have no clue how i would incorporate html into access...
 
Back
Top