Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何在msaccess 2003中为一系列值添加搜索条件_Sql_Vba_Ms Access - Fatal编程技术网

Sql 如何在msaccess 2003中为一系列值添加搜索条件

Sql 如何在msaccess 2003中为一系列值添加搜索条件,sql,vba,ms-access,Sql,Vba,Ms Access,我使用下面的代码过滤查询,以返回表单上搜索字段中输入的值 如何修改代码,以允许用户在搜索字段中搜索值大于或小于数字的记录 例如,用户输入60作为[OD]——我希望代码返回[OD]介于55和65之间的记录([60]+/-5) 由于我正在使用下面的addtowhere函数,我不知道如何修改此代码 有人能帮忙吗 Public Sub cmdSearch_Click() ' Create a WHERE clause using search criteria entered by user and

我使用下面的代码过滤查询,以返回表单上搜索字段中输入的值

如何修改代码,以允许用户在搜索字段中搜索值大于或小于数字的记录

例如,用户输入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
用户输入60作为[OD]——我希望代码返回记录 [OD]介于55和65之间([60]+/-5)

您可以为此使用Abs:

Where Abs([Enter OD] - [OD]) <= 5

Where Abs([Enter OD]-[OD])“Where[OD]介于(“&ArgCount-5&”和“&ArgCount+5&”)之间您好,您能解释一下如何将此添加到上述代码中吗,我已经在addtowhere[OD],“[OD]”上尝试过了。。。。。行,但它似乎不起作用Hi Gustav,我如何将其引入上述代码中?您可能需要修改
AddToWhere
函数来处理该问题。