使用VBA中的findfirst条件搜索多个字段访问

时间:2013-09-11 23:20:01

标签: vba ms-access-2010 criteria findfirst

以下代码在表单中找到匹配后在表单中填充值,在条件中,如何在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

1 个答案:

答案 0 :(得分:2)

  

如何在2个不同的字段中搜索该值? [IMEI和Mob_number]

您应该可以通过将语句更改为

来搜索两个字段
Criteria = "[MOB_NUMBER]='" & [Combo0] & "' OR [IMEI]='" & [Combo0] & "'"