无论是用
Data1.Recordset.FindFirst 方法
还是用
Data1.Recordset.FindNext 方法
来进行查找记录,都要使用
Data1.Recordset.NoMatch
来判断是否找到匹配的记录,如果
Data1.Recordset.NoMatch 返回 True,就表示没有找到,如果返回 False 就表示找到了。
而不能直接(最好不要直接)象你这样使用:
Data1.Recordset.FindNext "字段2 Like" & "'*" & Text8.Text & "*'"
Combo1.AddItem Data1.Recordset.Fields(1)
而是要这样:
Data1.Recordset.FindNext "字段2 Like" & "'*" & Text8.Text & "*'"
if Data1.Recordset.NoMatch Then
'这里编写终止继续查找的相应代码
else
Combo1.AddItem Data1.Recordset.Fields(1)
.........
End If
我上面说的最好不要直接象你这样使用,意思在有的地方还是可以直接使用的,那就是你确定查找的记录一定存在?
'添加一个TextBox(名为Text1, MultiLine属性设True,用来输入)、一个CommandButton(名为Command1,用来启动分析)、一个ListBox(名为List1,用来证明数组分析未出错)。
'添加如下代码。
Option Explicit
Private Sub Command1_Click()
Dim Num() As Long, i As Long, j As Long
List1.Clear
If StrToNum(Text1.Text, Num) Then
ReDim t(0 To UBound(Num, 2)) As String
For i = 0 To UBound(Num, 1)
For j = 0 To UBound(Num, 2)
t(j) = CStr(Num(i, j))
Next
List1.AddItem Join(t)
Next
Else
MsgBox "Wrong Input!"
End If
End Sub
Private Function StrToNum(S As String, N() As Long) As Boolean
Dim A() As String, B() As String, C As Long, D As String, E As Boolean, F As Long
Dim i As Long, j As Long
If Len(S) = 0 Then Exit Function
A = Split(S, vbCrLf)
For i = 0 To UBound(A)
Erase B
C = 0
E = False
For j = 1 To Len(A(i))
D = Mid(A(i), j, 1)
Select Case Asc(D)
Case 48 To 57
If Not E Then
ReDim Preserve B(0 To C)
C = C + 1
E = True
End If
B(C - 1) = B(C - 1) & D
Case 32
E = False
Case Else
Exit Function
End Select
Next
If C = 0 Then Exit Function
If i = 0 Then
ReDim N(0 To UBound(A), 0 To C - 1)
F = C
Else
If F C Then Exit Function
End If
For j = 0 To C - 1
N(i, j) = Val(B(j))
Next
Next
StrToNum = True
End Function
以上是使用VB循环查询数据库字符串并将其添加到下拉列表框的方法的详细内容。更多信息请关注PHP中文网其他相关文章!