在 VBA 中使用 findfirst 条件搜索多个字段访问
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18752909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Search multiple fields access using findfirst criteria in VBA
提问by user1687929
The following code is populating values on a form after it finds a match in a Mobile phone records table, in the criteria, how can I search for the value in 2 different fields? I could replace the combo box with a text box and would like to search in 2 fields, IMEI and Mob_number.
以下代码在手机记录表中找到匹配项后填充表单上的值,在条件中,如何在 2 个不同字段中搜索值?我可以用文本框替换组合框,并想在 2 个字段中进行搜索,IMEI 和 Mob_number。
Private Sub Combo0_AfterUpdate()
Dim D As Database
Dim rsmob As Recordset
Dim Criteria As String
Set D = CurrentDb
Set rsmob = D.OpenRecordset("Mobile_Phones", DB_OPEN_DYNASET)
Criteria = "[MOB_NUMBER]='" & [Combo0] & "'"
rsmob.FindFirst Criteria
Me!Location = rsmob("User_Name")
Me!MODEL = rsmob("Model")
Me!IMEI = rsmob("IMEI")
Me!DIR = rsmob("DIR")
Me!Status = rsmob("Status")
Me!Account = rsmob("ACCOUNT")
Me!Plan = rsmob("Plan")
Me!MobOrWifi = rsmob("Mob_Or_Wifi")
rsmob.Close
End Sub
采纳答案by Gord Thompson
how can I search for the value in 2 different fields? [IMEI and Mob_number]
如何在 2 个不同的字段中搜索值?[IMEI 和 Mob_number]
You should be able to search on two fields by changing your statement to
您应该能够通过将语句更改为在两个字段上进行搜索
Criteria = "[MOB_NUMBER]='" & [Combo0] & "' OR [IMEI]='" & [Combo0] & "'"