0

私はvbアクセスコードを使用してselect whereクエリを使用しています。レコードが一致するかどうかを確認するのに問題はありません.sTextboxがデータベースの値と一致しないかどうかに問題があります...「レコードが一致しません"一度だけですが、このステートメントでは、データベース内のレコードがすべて比較されるまで、MsgBox("No Record Match") が何度も出力されます...ステートメントを 1 回しか実行しないため、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

終了条件

4

2 に答える 2

0
Dim recordNotFound as Boolean = False
<Your While Loop>  
 ...

  If (sTextbox <> tQue) Then
        recordNotFound = True
        ''Or you can do something more complicated like recordNotFound = recordNotFound Or True depending on what you are trying to accomplish
        ''Problem lies here because it prints out MsgBox until the While loop is false...
    End If
 ...
<End Of your While Loop>

if recordNotFound Then MsgBox ("No Record Found")
于 2013-06-11T16:43:33.053 に答える
0
Dim MyDB As DAO.Database, MyRec As DAO.Recordset
Dim fQue As String, lQue As String, tQue As String

Set MyDB = CurrentDb

If Len(sTextbox)=0 Then
    MsgBox ("You must enter Value in Search Box")
    Exit Sub
End If

Set MyDB = CurrentDb

Set MyRec = MyDB.OpenRecordset("SELECT * From clientInfo where TowerUnit='" _
                                & sTextbox & "'")

If Not MyRec.EOF Then

    fQue = MyRec![FirstName]
    lQue = MyRec![LastName]
    tQue = MyRec![towerUnit]

    ClientTextbox.Value = lQue & ", " & fQue
    UnitTextbox.Value = tQue

Else

    MsgBox ("No Record Found")

End If
于 2013-06-11T17:35:31.027 に答える