我正在使用 Access 2003,我正在寻求有关使用表单中的复选框来填充文本字段的帮助。
我正在使用以下代码来获取复选框来填充文本字段。
Private Sub CAN_Click()
If Me.CAN = -1 Then
Me.[Subdirectorate Services] = "Community Adult Nursing"
Else
Me.[Subdirectorate Services] = ""
End If
Exit Sub
End Sub
我有大约 20 个复选框来记录一系列不同的服务,并且可以选择多个选项。当选择一个复选框并将所需文本传输到文本字段时,上述代码工作正常,但是当选中另一个复选框时,文本框中的前一个条目将被覆盖。
如何才能使文本框更新多个条目?
答案1
您可以
Me.[Subdirectorate Services] = "Community Adult Nursing"
使用
Me.[Subdirectorate Services] = Me.[Subdirectorate Services] & ", " & "Community Adult Nursing"
来连接多个值。
对于您的整个代码逻辑(不是正确的代码)将是:
Me.[Subdirectorate Services]=""
If Me.CAN = -1 Then _
Me.[Subdirectorate Services] = Me.[Subdirectorate Services] & ", " & "Community Adult Nursing"
If Me.CAN2 = -1 Then _
Me.[Subdirectorate Services] = Me.[Subdirectorate Services] & ", " & "text 2"
...
If Me.[Subdirectorate Services] <> "" then _
Me.[Subdirectorate Services] = Left(Me.[Subdirectorate Services]="",Len(Me.[Subdirectorate Services]="")-2)
最后一行是,
从字符串末尾删除的。