Private Sub Form1_Load() Dim cn As New ADODB.Connection, rs As New ADODB.Recordset cn.Open "......" set rs = cn.execute ("select ditinct year([date]) from yourtable order by year([date])") Do Until rs.EOF Combo1.Add rs.Fields(0) rs.MoveNext Loop If Combo1.ListCount Then Combo1.ListIndex = 0 rs.Close Set rs = Nothing cn.Close Set cn = Nothing End SubPrivate Sub Combo1_Click() Dim cn As New ADODB.Connection, rs As New ADODB.Recordset cn.Open "......" set rs = cn.execute ("select ditinct Month([date]) from yourtable where year([date])=" & Combo1.Text & " order by Month([date])") Combo2.Clear Do Until rs.EOF Combo2.Add rs.Fields(0) rs.MoveNext Loop If Combo2.ListCount Then Combo2.ListIndex = 0rs.Close Set rs = Nothing cn.Close Set cn = Nothing End SubPrivate Sub Combo2_Click() Dim cn As New ADODB.Connection, rs As New ADODB.Recordset cn.Open "......" set rs = cn.execute ("select ditinct Day([date]) from yourtable where year([date])=" & Combo1.Text & " and Month([date])=" & Combo2.Text & " order by Day([date])") Combo3.Clear Do Until rs.EOF Combo3.Add rs.Fields(0) rs.MoveNext Loop If Combo3.ListCount Then Combo2.ListIndex = 0rs.Close Set rs = Nothing cn.Close Set cn = Nothing End Sub
select ditinct year(datefileld) as 年份, month(datefield) as 月份 from yourtable order by year(datefileld), month(datefield)
2005-09-08 18:00:35 报警
2005-11-05 10:41:32 已消除
2006-09-14 09:55:40 报警
2006-11-05 10:42:31 报警
2007-02-14 15:57:07 已消除比如它数据库中的值是这样子的
我现在要做一个查询,三个组合框,分别代表年、月、日
现在基本上是做出来了,不过我点击2005年时,月的组合框里出现了
02月、09月、11月,02月是它没有,我想点击哪一年时,月那里就出现
它自己有的那几个月,不要把数据库所有的月都包括进去!希望各位大侠帮帮忙!
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.Open "......"
set rs = cn.execute ("select ditinct year([date]) from yourtable order by year([date])")
Do Until rs.EOF
Combo1.Add rs.Fields(0)
rs.MoveNext
Loop
If Combo1.ListCount Then Combo1.ListIndex = 0
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End SubPrivate Sub Combo1_Click()
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.Open "......"
set rs = cn.execute ("select ditinct Month([date]) from yourtable where year([date])=" & Combo1.Text & " order by Month([date])")
Combo2.Clear
Do Until rs.EOF
Combo2.Add rs.Fields(0)
rs.MoveNext
Loop
If Combo2.ListCount Then Combo2.ListIndex = 0rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End SubPrivate Sub Combo2_Click()
Dim cn As New ADODB.Connection, rs As New ADODB.Recordset
cn.Open "......"
set rs = cn.execute ("select ditinct Day([date]) from yourtable where year([date])=" & Combo1.Text & " and Month([date])=" & Combo2.Text & " order by Day([date])")
Combo3.Clear
Do Until rs.EOF
Combo3.Add rs.Fields(0)
rs.MoveNext
Loop
If Combo3.ListCount Then Combo2.ListIndex = 0rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub