Salve a tutti,
Posto anch'io la mia versione, giusto per divertimento, ovviamente.
Funziona con un numero arbitrario di CheckBox, sempre che seguano la nomenclatura chkAllegato[x]
Function CheckAttachments()
Dim ctl As Control, idx As Long
Dim arrAllegati() As String, strAllegati As String
For Each ctl In Me.Controls
If TypeOf ctl Is CheckBox And InStr(ctl.Name, "chkAllegato") > 0 Then
If ctl.Value Then
ReDim Preserve arrAllegati(idx)
arrAllegati(idx) = "Allegato " & Right(ctl.Name, 1)
idx = idx + 1
End If
End If
Next ctl
strAllegati = Join(arrAllegati, ", ")
If strAllegati <> "" And InStr(strAllegati, ",") > 0 Then
strAllegati = Mid(strAllegati, 1, InStrRev(strAllegati, ",") - 1) & " e" & Mid(strAllegati, InStrRev(strAllegati, ",") + 1)
CheckAttachments = "Istanza, " & strAllegati
ElseIf strAllegati <> "" Then
CheckAttachments = "Istanza e " & strAllegati
Else
CheckAttachments = "Istanza."
End If
End Function