伙计们,我正在使用 select where 使用 vb 访问代码进行查询,我检查记录是否匹配没有问题,如果 sTextbox 与数据库中的值不匹配,我遇到问题......它应该打印“No Record Match " 仅一次,但在此语句中,它会多次打印出 MsgBox("No Record Match") 直到数据库中的记录已全部比较...我无法添加 Exit Do,因为它只会运行该语句一次并且它不会将 sTextbox 与数据库的所有值进行比较......我不允许使用任何其他方式,除了 sql 查询语句。非常感谢您的帮助。
Dim MyDB As DAO.Database, MyRec As DAO.Recordset, MyList As String
Dim fQue As String, lQue As String, tQue As String
Set MyDB = CurrentDb
If IsNull(sTextbox) Or sTextbox = "" Then
MsgBox ("You must enter Value in Search Box")
End If
If (sTextbox <> "") Or (sTextbox <> "") Then
MsgBox ("There is value")
Set MyDB = CurrentDb
Set MyRec = MyDB.OpenRecordset("SELECT * From clientInfo")
Do While Not MyRec.EOF 'Loop to check if sTextbox = tQue
fQue = MyRec![FirstName]
lQue = MyRec![LastName]
tQue = MyRec![towerUnit]
MyRec.MoveNext
If (sTextbox = tQue) Then
Set MyDB = CurrentDb
Set MyRec = MyDB.OpenRecordset("SELECT * From clientInfo where TowerUnit='" & sTextbox & "'")
FullName = lQue & ", " & fQue
MsgBox (FullName)
ClientTextbox.Value = lQue & ", " & fQue
UnitTextbox.Value = tQue
Exit Do
End If
If (sTextbox <> tQue) Then
MsgBox ("No Record Found")
''Problem lies here because it prints out MsgBox until the While loop is false...
End If
Loop
万一