Shannan Casteel via AccessMonster.com wrote:
rkc,
No...to your first question.
Yes...to your second question.
I have almost gotten it to work using the following code, but it won't let me
have a zero length string.
For Check box called CheckAirCleaner:
Private Sub CheckAirCleaner_Click()
If Me.CheckAirCleaner = True Then
Me.TextProblemSubcategory = (ProblemSubcategory) & "Air Cleaner;"
Else
If Me.TextProblemSubcategory.Value <> "" Then
Me.TextProblemSubcategory.Value = "NA"
End If
End If
End Sub
I can save you a bit of time and effort with this, but after reading
another post of yours on the same subject I think you may have a
table design problem.
Any way, paste the following code into your form's code module.
After you have done that, open your form in design view and
select all the checkboxes that you want to have the desired
behaviour. Once you have done that click the properties icon,
select the Events tab, scroll to the On Click Event and enter
=updateProblemSubcategory().
Close the property sheet and give the form a try.
'---- start of code ----
Function updateProblemSubcategory()
Dim sCaption As String
Dim sac As Access.Control
'find the caption of the label
Set sac = Screen.ActiveControl
sCaption = getLabelCaption(sac)
With Me.TextProblemSubcategory
Select Case sac.value
Case vbTrue 'add the caption
If Len(.value & vbNullString) > 0 Then
.value = .value & ";"
End If
.value = .value & sCaption
Case vbFalse 'remove the caption
.value = Replace(.value, sCaption, "")
If InStr(.value, ";;") > 0 Then
.value = Replace(.value, ";;", ";")
End If
If left$(.value, 1) = ";" Then
.value = Mid$(.value, 2)
End If
If Right$(.value, 1) = ";" Then
.value = left$(.value, Len(.value) - 1)
End If
Case Else
'nothing
End Select
End With
Set sac = Nothing
End Function
Private Function getLabelCaption(xs As Access.Control) As String
'returns the caption of the label attached
'to the control argument if it exists.
Dim ctl As Access.Control
For Each ctl In Me.Controls
If ctl.ControlType = acLabel Then
If ctl.parent.Name = xs.Name Then
getLabelCaption = ctl.Caption
Exit For
End If
End If
Next
Set ctl = Nothing
End Function
'---- end of code ----