如何用TreeView控件显示Access数据库中年月日的内容。
如:
1999
|__一月
| |__1日
| |__2日
| ………
|__二月
|__1日
|__2日
最好是数据库中有三个字段分别保存年月日
Public Sub AddNodes()
Dim strkey As String
Dim mNodes As MSComctlLib.Nodes
Dim mNode1 As MSComctlLib.Node
Dim mNode2 As MSComctlLib.Node
Dim I As Long
On Error Resume Next
Set mNodes = tvwMain.Nodes
Dim rs1 As ADODB.Recordset
Set rs1 = New ADODB.Recordset
With rs1
Set .ActiveConnection = conn
.CursorLocation = adUseClient
.Source = "select id,mc from lb order by ID"
.LockType = adLockReadOnly
.CursorType = adOpenForwardOnly
.Open
End With
mNodes.Clear
With rs1
If .EOF And .BOF Then
Set rs1 = Nothing
Exit Sub
End If
For r = 1 To .RecordCount
strkey = "o" & .Fields("ID")
Set mNode1 = mNodes.Add(, , strkey, .Fields("mc") & "", 7, 7)
第二层循环
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
strsql = "select * from ws where mid=" & .Fields("id")
rs.Open strsql, conn, adOpenStatic, adLockPessimistic
For j = 1 To rs.RecordCount
Key = "t" & rs.Fields("id")
Set mNode2 = mNodes.Add(mNode1.Index, tvwChild, Key, rs.Fields("mc"), 7, 7)
rs.MoveNext
Next
.MoveNext
Next
.Close
End With
Set rstNodes = Nothing
On Error GoTo 0
End Sub
不分也可以,但你要自定义一个函数分别取出年、月、日。再结合楼上的应该就可以了。
数据库中 字段 日期
Option Explicit
Private Sub Command1_Click()
Dim i As Long
Dim j As Long
Dim n As Long
For i = 1998 To 2002
DoEvents
For j = 1 To 12
For n = 1 To 31
If IsDate(Str(i) & "-" & Str(j) & "-" & Str(n)) Then
Debug.Print Str(i) & "年"
Debug.Print Str(j) & "月"
Debug.Print Str(n) & "日"
Debug.Print "================="
End If
Next
Next
Next
End Sub