If Not rs_data2.EOF Then
rs_data2.MoveFirst
Do While Not rs_data2.EOF
.Row = .Row + 1
.Col = 0
If Not IsNull(rs_data2.Fields(0)) Then .Text = rs_data2.Fields(0) Else .Text = \.Col = 1 If Not IsNull(rs_data2.Fields(1)) Then .Text = rs_data2.Fields(1) Else .Text = \.Col = 2 If Not IsNull(rs_data2.Fields(2)) Then .Text = rs_data2.Fields(2) Else .Text = \.Col = 3 If Not IsNull(rs_data2.Fields(3)) Then .Text = rs_data2.Fields(3) Else .Text = \.Col = 4 If Not IsNull(rs_data2.Fields(4)) And CDbl(rs_data2.Fields(4)) < 0 Then .Text = -CDbl(rs_data2.Fields(4)) Else .Text = rs_data2.Fields(4) End If .Col = 5 If Not IsNull(rs_data2.Fields(5)) Then .Text = rs_data2.Fields(5) Else .Text = \.Col = 6 If Not IsNull(rs_data2.Fields(6)) Then .Text = rs_data2.Fields(6) Else .Text = \ .Col = 7
If Not IsNull(rs_data2.Fields(7)) And CDbl(rs_data2.Fields(4)) < 0 Then
.Text = -CDbl(rs_data2.Fields(7)) Else
.Text = rs_data2.Fields(7)
End If .Col = 8 If Not IsNull(rs_data2.Fields(8)) Then .Text = rs_data2.Fields(8) Else .Text = \rs_data2.MoveNext Loop rs_data2.MoveLast End If End With End Sub (5) 查询子窗体代码 查询子窗体是用来查询库房中图书资料明细的。其运行效果如图41所示。
图41 查询子窗体运行效果 在列表框中给出编号或年月日后,“查询”按钮的Click事件将给出与数据库查找比较的结果。
Private Sub Command1_Click()
On Error GoTo cmderror
Dim find_date1 As String
Dim find_date2 As String
If Option1.Value = True Then sqlfind = \图书资料 where 编号 between '\Combo1(0).Text &\End If If Option2.Value = True Then find_date1 = Format(CDate(Comboy(0).Text &\Combom(0).Text &\find_date2 = Format(CDate(Comboy(1).Text &\Combom(1).Text &\sqlfind = \图书资料 where 购买日期 between #\find_date1 &\End If rs_data1.Open sqlfind, conn, adOpenKeyset, adLockPessimistic frmdatamanage.displaygrid1 Unload Me cmderror: If Err.Number <> 0 Then MsgBox Err.Description
End If
End Sub
运行查询子窗体时,组合框中就已经从数据库中提取了货单号和年月日两个待查条件。
Dim i As Integer
Dim sql As String If findok = True Then rs_data1.Close End If sql = \图书资料 order by 编号 desc\rs_find.CursorLocation = adUseClient rs_find.Open sql, conn, adOpenKeyset, adLockPessimistic If rs_find.EOF = False Then ' 添加编号 With rs_find Do While Not .EOF Combo1(0).AddItem .Fields(0) Combo1(1).AddItem .Fields(0) .MoveNext Loop End With End If For i = 2001 To 2005 ' 添加年 Comboy(0).AddItem i