gpt4 book ai didi

database - 根据带有 if 条件的多个文本框值将值分配给表单上的文本框 - MS ACCESS

转载 作者:搜寻专家 更新时间:2023-10-30 20:26:42 24 4
gpt4 key购买 nike

让我解释一下,我在表单上有如下字段(文本框)

textbox1 = can hold Yes or NO
textbox2 = can hold Yes or NO
textbox3 = can hold Yes or NO
textbox4 = can hold Yes or NO

textboxResult 仅保存值为"is"的那些文本框的标签(标题)的串联值

我已经尝试了很多可能的解决方案(在我看来),包括以下但没有成功。还使用 OR 运算符测试了以下代码。

If Me.textbox1.Value = "Yes" And Me.textbox2.Value = "Yes" And _
Me.textbox3.Value = "Yes" And Me.textbox4.Value = "Yes" Then
Me.textboxResult.Value = Me.Label1.Caption & "," &
Me.Label2.Caption & "," & Me.Lable3.Caption & "," &
Me.Label4.Caption
Else
Me.textboxResult.Value = "NA"
End If

我想为那些值为 YES 的文本框分配标签的标题。请帮忙

最佳答案

如果我理解正确,您需要所有 TextBox 标签的串联值。因此,批量 AND 可能不是选项,也许检查每个控件。类似的东西。

Dim txtResult As String

If Me.textbox1 = "Yes" Then _
txtResult = txtResult & Me.textbox1.Controls.Item(0).Caption & ","

If Me.textbox2 = "Yes" Then _
txtResult = txtResult & Me.textbox2.Controls.Item(0).Caption & ","

If Me.textbox3 = "Yes" Then _
txtResult = txtResult & Me.textbox3.Controls.Item(0).Caption & ","

If Me.textbox4 = "Yes" Then _
txtResult = txtResult & Me.textbox4.Controls.Item(0).Caption & ","

If Len(txtResult) > 0 Then
Me.textboxResult = Left(txtResult, Len(txtResult)-1)
Else
Me.textboxResult = "NA"
End If

注意 - Me.TextBoxName.Controls.Item(0) 将返回带有 TextBoxName 的关联标签。如果文本框没有关联,那么您可能会遇到错误。


编辑 - 编辑后,如果您只想使用标签的标题,只需将 Me.textbox.Controls(0).Caption 替换为 我.LableName.Caption

关于database - 根据带有 if 条件的多个文本框值将值分配给表单上的文本框 - MS ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30618192/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com