【发布时间】:2016-08-03 23:04:36
【问题描述】:
我有一个访问数据库,它有一个带有一些文本框和一些复选框的搜索表单。 用户通过输入文本或选中其中一个框来选择要在搜索表单上收集哪些值。单击搜索按钮时,会打开相应的结果表单。
结果表单的数据源是一个查询,它给出了表中与请求的搜索相对应的记录列表。在查询中,我有 2 个 IIf 字段,1 将 2 个复选框组合成一个文本句子,表示在记录中选中的这 2 个框中的一个或两个,另一个组合 3 个复选框。结果表单上有 2 个文本字段,其数据源是 2 个 IIf 查询字段。
结果表单上有第三个(未绑定)文本字段,我还有 9 个剩余的复选框,我需要将它们组合成该字段的一个句子。我已经在结果表单的打开事件中尝试了这个功能(Oth)。该函数似乎有效,因为它在 MsgBox(fOther) 中为每条记录提供了正确的句子,但我无法让 fOther 填充结果表单上的未绑定文本字段。我已经尝试了几种不同的方式,表单的记录集,查询的,表格的。我尝试在模块中放置一个(类似的)函数,并在更新查询中使用该函数来获取表中的字段。我无法填充该(其他)字段。我已经尝试在该(其他)文本字段的查询中构建一个 IIf 字段,这对于 9 个对象和所有可能的组合来说非常令人生畏,我什至不确定它是否可能。有什么建议可以提供吗?
Private Sub Oth()
Dim strOthr(9) As String
Dim Tt As Integer
Dim fOther As String
Me.Recordset.MoveFirst
Do While Not Recordset.EOF
If Me.[o-180] Then
strOthr(0) = "180"
End If
If Me.[o-e] Then
strOthr(1) = "Education"
End If
If Me.[o-rcb-f] Then
strOthr(2) = "Flag"
End If
If Me.[o-rcb-m] Then
strOthr(3) = "Medal"
End If
If Me.[o-rcb-b] Then
strOthr(4) = "Burial"
End If
If Me.[o-ra-hb] Then
strOthr(5) = "Health Benefits"
End If
If Me.[o-ra-t] Then
strOthr(6) = "Transportation"
End If
If Me.[o-ra-hl] Then
strOthr(7) = "Home Loans"
End If
If Me.[o-ra-il] Then
strOthr(8) = "Income Letter"
End If
For Tt = 0 To 8
If Len(strOthr(Tt)) > 0 Then
If Len(fOther) > 0 Then
fOther = fOther & ", " & strOthr(Tt)
Else
fOther = fOther & strOthr(Tt)
End If
End If
Next Tt
Me.Other = fOther
MsgBox fOther
For Tt = 0 To 8
strOthr(Tt) = ""
Next Tt
fOther = ""
Me.Recordset.MoveNext
Loop
End Sub
【问题讨论】:
-
为什么不让结果表单成为搜索表单的子表单,而让其他表单成为搜索表单上的未绑定控件?
标签: ms-access