我有一个搜索表单,链接到一个表格,显示基于位置的员工数量,从两个组合框(州和办公室)中选择
我使用以下代码进行搜索:
Private Sub command90_Click()
Dim strsearch As String
Dim Task As String
'Check if a keyword entered or not
If IsNull(Me.office.Value) Or IsNull(Me.state.Value) Then
MsgBox "Please select an office", vbOKOnly, "Keyword Needed"
Me.office.BackColor = vbYellow
Me.state.BackColor = vbYellow
Me.state.SetFocus
Else
strsearch = Me.office.Value
'Task = "SELECT * FROM table1 WHERE ((officename Like ""*" & strsearch & "*""))"
Task = "SELECT * FROM table1 WHERE officename = Me.office.Value"
Me.RecordSource = Task
Me.office.BackColor = vbWhite
Me.state.BackColor = vbWhite
End If
Form!office.SetFocus
End Sub
在此之前,我使用了LIKE *来查找员工人数,但在办公室名称相似时遇到了麻烦。(上面注明了')
因此,为了返回确切的结果,我决定使用组合框,并将搜索项限制为组合框值。 但是现在一个框显示“输入参数”,如果输入完全确实,确实会返回确切的结果,但会失去组合框的便利性。
如何设置以使输入参数框不显示,而是仅使用组合框值运行搜索?
答案 0 :(得分:0)
Task = "SELECT * FROM table1 WHERE officename = '" & Me!office.Value & "'"
MSDN(Microsoft): Everything About Using Parameters from Code
Allen Browne的回答: Using Form Control values in Queries