我使用下面的代码过滤查询,以返回在表单上的搜索字段中输入的值。
如何修改代码,以允许我的用户在搜索字段中搜索值大于或小于某个数字的记录。
例如用户输入60作为[OD] - 我希望代码返回[OD]在55到65之间的记录([60] +/- 5)。
由于我正在使用下面的addtowhere函数,我不知道如何修改此代码。
任何人都可以帮忙吗?
Public Sub cmdSearch_Click()
' Create a WHERE clause using search criteria entered by user and
' set RecordSource property of SEARCH QUOTE SUBform.
If Me.[Goodsinsub].Form.Recordset.RecordCount = 0 Then Me.Goodsinsub.Form.Command95.Visible = False Else Me.Goodsinsub.Form.Command95.Visible = True
Dim MySQL As String, MyCriteria As String, myrecordsource As String
Dim ArgCount As Integer
Dim tmp As Variant
Dim mycontrol As Control
' Initialize argument count.
ArgCount = 0
' Initialize SELECT statement.
MySQL = "SELECT * FROM [qry_tubes out] WHERE"
MyCriteria = ""
' Use values entered in text boxes in form header to create criteria for WHERE clause.
AddToWhere [Combo30], "[product]", MyCriteria, ArgCount
AddToWhere [OD], "[OD]", MyCriteria, ArgCount
AddToWhere [ID], "[ID]", MyCriteria, ArgCount
AddToWhere [LG], "[LG]", MyCriteria, ArgCount
' If no criterion specifed, return all records.
If MyCriteria = "" Then
MyCriteria = "True"
End If
' Create SELECT statement.
myrecordsource = MySQL & MyCriteria
' Set RecordSource property of Find Customers Subform.
Me![Goodsinsub].Form.RecordSource = myrecordsource
' If no records match criteria, display message.
' Move focus to Clear button.
If Me![Goodsinsub].Form.RecordsetClone.RecordCount = 0 Then
tmp = EnableControls("detail", True)
MsgBox "No records found"
Else
' Enable control in detail section.
tmp = EnableControls("Detail", True)
' Move insertion point to Find Customers Subform.
Me![Goodsinsub].Visible = True
End If
End Sub
答案 0 :(得分:0)
用户输入60作为[OD] - 我希望代码返回记录 [OD]在55到65之间([60] +/- 5)。
您可以使用 Abs :
Where Abs([Enter OD] - [OD]) <= 5