|
本帖最后由 Aкon 于 2011-8-10 14:01 编辑
请高手们帮我看一下这段代码,如何不受12个月限制:谢谢!
Dim i As Long, n As Long
Dim arr
If DTPicker5 = "" Then GoTo ErrHandler
arr = Split(DTPicker5)
Dim DD As Date
If arr(0) > 12 Then MsgBox "请检查您输入的月份,不能超过12月。": Exit Sub
If arr(0) > 12 Then MsgBox "请检查您输入的日期,不能超过31号。": Exit Sub
DD = Year(Date) & "-" & arr(0) & "-" & arr(1)
Me.ListView1.ListItems.Clear
ErrHandler:
For i = 3 To Sheet1.[b2].End(4).Row
If DateDiff("d", Sheet1.Cells(i, "B"), DD) = 0 Or TextBox1 = "" Then
n = n + 1
2: 'Listview添加数据
With Me.ListView1.ListItems.Add()
.Text = Format(Sheet1.Cells(i, "B"), "yyyy年m月d日") '第一项添加日期
.SubItems(1) = Sheet1.Cells(i, "C") '报表第二项为C列,以下略
.SubItems(2) = Sheet1.Cells(i, "D")
.SubItems(3) = Sheet1.Cells(i, "E")
.SubItems(4) = Sheet1.Cells(i, "F")
End With
End If
Next
If n = 0 Then MsgBox "你输入的查询日期无记录,请重新输入您要查询的日期!": TextBox1 = "": TextBox1.SetFocus
End Sub
回复 Aкon 的帖子
- Private Sub CommandButton1_Click()
- Dim i As Long, n As Long
- Dim arr
- If DTPicker5 = "" Then Exit Sub
- Dim DD As Date
- DD = DTPicker5.Value
- Me.ListView1.ListItems.Clear
- For i = 3 To Sheet1.[b2].End(4).Row
- If Sheet1.Cells(i, "B") = DD Then
- n = n + 1
- 'Listview添加数据
- With Me.ListView1.ListItems.Add()
- .Text = Format(Sheet1.Cells(i, "B"), "yyyy年m月d日") '第一项添加日期
- .SubItems(1) = Sheet1.Cells(i, "C") '报表第二项为C列,以下略
- .SubItems(2) = Sheet1.Cells(i, "D")
- .SubItems(3) = Sheet1.Cells(i, "E")
- .SubItems(4) = Sheet1.Cells(i, "F")
- End With
- End If
- Next
- If n = 0 Then
- MsgBox "你输入的查询日期无记录,请重新输入您要查询的日期!"
- Me.ListView1.ListItems.Clear
- DTPicker5 = Date
- DTPicker5.SetFocus
- End If
- End Sub
复制代码
|
|