以下是引用xzlxzlxzl在2017-2-10 10:54:53的发言:
这个应该可以用两个查询语句完成,首先做年的查询,代码如下:
rs.Open "SELECT left(" + Title(3) + ",4) as nian FROM [" & SheetName & "$] group by left(" + Title(3) + ",4)", cn, adOpenStatic
ComboTime(0).clear
while not rs.eof
ComboTime(0).additem rs("nian") '这样会将你示例数据的2012、2013、2014添加进用来表示年的combbox里
rs.movenext
wend
在ComboTime_click事件里写下述代码,可以把选择的年份包含的月份添加进另一个combbox里
private sub ComboTime_click(Index As Integer)
if index=0 then
rs.Open "SELECT right(" + Title(3) + ",2) as yue FROM [" & SheetName & "$] where "+Title(3)+"like " + combotime(0) + "* group by right(" + Title(3) + ",2)", cn, adOpenStatic
ComboTime(1).clear
while not rs.eof
ComboTime(1).additem rs("yue") '这样会将你示例数据相应年份所包含的月份添加进用来表示月的combbox里,如2012年就只有01至04
rs.movenext
wend
endif
end sub
好像不行~但是不知道哪里有问题~
程序代码:
Dim cn As New ADODB.Connection, RS As New ADODB.Recordset, DDX As Integer, NYFX() As String, I As Integer
Private Sub A()
RS.Open "SELECT left(" + "MONTH" + ",4) as nian FROM [" & "RawData" & "$] group by left(" + "MONTH" + ",4)", cn, adOpenStatic
ComboTime(0).Clear
While Not RS.EOF
ComboTime(0).AddItem RS("nian")
RS.MoveNext
Wend
Set RS = Nothing
End Sub
Private Sub ComboTime_Click(Index As Integer)
Dim Title(3) As String
Title(3) = "MONTH"
If Index = 0 Then
RS.Open "SELECT right(" + Title(3) + ",2) as yue FROM [" & SheetName & "$] where " + Title(3) + " like " + ComboTime(0).Text + "* group by right(" + Title(3) + ",2)", cn, adOpenStatic
ComboTime(1).Clear
While Not RS.EOF
ComboTime(1).AddItem RS("yue")
RS.MoveNext
Wend
Set RS = Nothing
End If
End Sub
Private Sub Form_Load()
cn.Open "Data Source=" + App.Path + "\11111.xlsx" + ";" + "Provider=" + "Microsoft.ACE.OLEDB.12.0;" + "Extended Properties=" + "'Excel 12.0;" + "HDR=" + "Yes" + "IMEX=" + "1';"
Call A
End Sub
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
图片附件: 游客没有浏览图片的权限,请
登录 或
注册