跟踪后,你的提示出现在这个部分:
Private Sub Form_Load()
Dim n As Integer
n = ListView1.ListItems.Count
If n <= 0 Then
MsgBox "没有输入物料编码", vbInformation, "提示"
Exit Sub
End If
是 Form5 的初始化部分,你总抓着前面的去弄,当然找不对。
---------------------------------------------
m = FormatDateTime(Now(), vbShortDate)
m = Left(m, 4)
n = Val(m)
Combo2.AddItem n - 1 & "年"
Combo2.AddItem n & "年"
Combo2.AddItem n + 1 & "年"
For i = 1 To 12
Combo3.AddItem i & "月"
Next
For i = 1 To 31
Combo4.AddItem i & "日"
Next
Combo9.AddItem n - 1 & "年"
Combo9.AddItem n & "年"
Combo9.AddItem n + 1 & "年"
For i = 1 To 12
Combo10.AddItem i & "月"
Next
For i = 1 To 31
Combo11.AddItem i & "日"
Next
这一大段代码都要简化。
首先,取年:
n = Year(Now())
然后,添加年和月的代码,可以并到一起。
For i = n-1 To n+1
Combo2.AddItem i & "年"
Combo9.AddItem i & "年"
Next i
For i = 1 To 12
Combo3.AddItem i & "月"
Combo10.AddItem i & "月"
Next
日期,建议使用动态添加,而不在窗体初始化过程中加入。
如这个过程改一下,
Private Sub Combo2_Click()
If Combo2.ListIndex > -1 And Combo3.ListIndex > -1 Then
Combo4.Clear
Dim i As Long
For i = 1 To Day(DateSerial(Val(Combo2.Text), Val(Combo3.Text) + 1, 0))
Combo4.AddItem i & "日"
Next i
Showcom
End If
End Sub
Private Sub Combo3_Click()
If Combo2.ListIndex > -1 And Combo3.ListIndex > -1 Then
Combo4.Clear
Dim i As Long
For i = 1 To Day(DateSerial(Val(Combo2.Text), Val(Combo3.Text) + 1, 0))
Combo4.AddItem i & "日"
Next i
Showcom
End If
End Sub
对应,9 10 二个combo 也相应修改一下。