我有这段代码可以使用 MS Access 创建多字段搜索表单,并引用语法错误;
Private Sub cmdSearch_Click()
On Error GoTo errr
Me.infot_subform1.Form.RecordSource = " select * from infot " & BuildFilter
Me.infot_subform1.Requery
Exit Sub
errr:
MsgBox Err.Description
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim tmp As String
tmp = """"
Const conJetDate = "\#dd\/mm\/yyyy\#"
varWhere = Null
If Me.txtID > "" Then
varWhere = varWhere & "[ID] like" & Me.txtID & "AND"
End If
If Me.txtName > "" Then
varWhere = varWhere & "[Name] like" & tmp & Me.txtName & tmp & "AND"
End If
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "Where" & varWhere
If Right(varWhere, 5) = "AND" Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function