程序代码:
Option Explicit
Dim conn As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim rs2 As New ADODB.Recordset
Dim rs3 As New ADODB.Recordset
Dim Str1 As String
Dim Str2 As String
Dim Str3 As String
Dim strSQL As String
Dim remark As String
Private Sub Combo1_Click()
strSQL = "select * from 表1 where 备注=" & "'" & Combo1.Text & "'"
rs2.Open strSQL, conn, 1, 1
Set MSHFlexGrid1.DataSource = rs2
rs2.Close
End Sub
Private Sub Combo2_Click()
strSQL = "select * from 表1 where 备注=" & "'" & Combo1.Text & "' and 数量=" & "'" & Combo2.Text & "'"
rs2.Open strSQL, conn, 1, 1
Set MSHFlexGrid1.DataSource = rs2
rs2.Close
End Sub
Private Sub Form_Load()
Dim i As Long
Dim exist1 As Boolean
Dim exist2 As Boolean
Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
Str2 = "Data Source=c:\test.mdb;"
Str3 = "Jet OLEDB:Database Password="
conn.Open Str1 & Str2 & Str3
strSQL = "select * from 表1 "
rs1.Open strSQL, conn, 1, 1
Set MSHFlexGrid1.DataSource = rs1
Me.Show
Do While Not rs1.EOF
exist1 = False
exist2 = False
For i = 0 To rs1.RecordCount
If (rs1("备注") = Combo1.List(i)) Then exist1 = True: Exit For
Next
If exist1 = False Then Combo1.AddItem rs1("备注")
For i = 0 To rs1.RecordCount
If (rs1("数量") = Combo2.List(i)) Then exist2 = True: Exit For
Next
If exist2 = False Then Combo2.AddItem rs1("数量")
rs1.MoveNext
Loop
Combo1.Text = "Please select"
Combo2.Text = "Please select"
End Sub
按你情况修改以上代码并添加相关释放、关闭语句,试试。
也可以建临时表查询select * into 临时表 from 表名
然后再select * from 临时表 where ...
最后drop table 临时表。