private FistDay as string
Private Sub CountMoney() '如果今天是1号,则要将数据插入财务收支表
Dim D As Integer
Dim Y, M As String
D = CInt(Day(Date))
If D = 1 Then
Y = CStr(Year(Date))
M = CStr(Month(Date))
End If
Debug.Print CDate(Y & "-" & M & "-" & "1")'此处就有错误(类型错误),该怎么写呢?
FirstDay = Format(CDate(Y & "-" & M & "-" & "1"), "yyyy-mm-dd")
End Sub
Private Sub SeekRepair()
Dim M As String
If Month(Date) < 10 Then
M = "0" + CStr(Month(Date))
End If
YTime = CStr(Year(Date)) + M
Call execDatabase
Call CountMoney
txtSQL = "select sum(维修费用) from 维护维修表 where 维修时间>'" & CDate(FirstDay) - 31 & "'and 维修时间<'" & FirstDay & "'"
Debug.Print txtSQL
conn.Execute txtSQL
rs.Open txtSQL, conn, adOpenStatic, adLockOptimistic
End Sub
是为了统计上个月维修费用的总和.
这样统计有些可能不够准确,有什么别的好方法吗?
Private Sub CountMoney() '如果今天是1号,则要将数据插入财务收支表
Dim D As Integer
Dim Y, M As String
D = CInt(Day(Date))
If D = 1 Then
Y = CStr(Year(Date))
M = CStr(Month(Date))
End If
Debug.Print CDate(Y & "-" & M & "-" & "1")'此处就有错误(类型错误),该怎么写呢?
FirstDay = Format(CDate(Y & "-" & M & "-" & "1"), "yyyy-mm-dd")
End Sub
Private Sub SeekRepair()
Dim M As String
If Month(Date) < 10 Then
M = "0" + CStr(Month(Date))
End If
YTime = CStr(Year(Date)) + M
Call execDatabase
Call CountMoney
txtSQL = "select sum(维修费用) from 维护维修表 where 维修时间>'" & CDate(FirstDay) - 31 & "'and 维修时间<'" & FirstDay & "'"
Debug.Print txtSQL
conn.Execute txtSQL
rs.Open txtSQL, conn, adOpenStatic, adLockOptimistic
End Sub
是为了统计上个月维修费用的总和.
这样统计有些可能不够准确,有什么别的好方法吗?
Debug.Print Y & "-" & M & "-" & "1"
仍有类型错误!
Dim Y As String, M As String
D = CInt(Day(Now))
If D = 1 Then
Y = CStr(Year(Now))
M = CStr(Month(Now))
debug CDate(Y & "-" & M & "-" & "01") '此处就有错误(类型错误),该怎么写呢?
debug Format((Y & "-" & M & "-" & "01"), "yyyy-mm-dd")
End If
txtSQL = "select sum(维修费用) from 维护维修表 where 维修时间>='" & CDate(FirstDay) - 31 & "'and 维修时间<='" & FirstDay & "'"
原来是if d=1 then出了问题(原来本来是用来判断的结果没删除这句,所有才会出错),晴明说的正确.
各位有没有别的什么方法得到比较精确的值呢?(最好是不要去判断这个月是否有31天的那种.)
我是指维修时间>='" & CDate(FirstDay) - 31 & "'
回答出来就解贴.
txtSQL = "select sum(维修费用) from 维护维修表 where datepart(month,维修时间)=datepart(month,dateadd(month,-1,getdate()))"
那条件多余!!
Private Sub CountMoney() '如果今天是1号,则要将数据插入财务收支表
Dim D As Integer
Dim Y, M As String
D = CInt(Day(Date))
If D = 1 Then
Y = CStr(Year(Date))
M = CStr(Month(Date))
End If
Debug.Print CDate(Y & "-" & M & "-" & "1")'此处就有错误(类型错误),该怎么写呢?
FirstDay = Format(CDate(Y & "-" & M & "-" & "1"), "yyyy-mm-dd")
End Sub
Private Sub SeekRepair()
Dim M As String
If Month(Date) < 10 Then
M = "0" + CStr(Month(Date))
End If
YTime = CStr(Year(Date)) + M
Call execDatabase
Call CountMoney
txtSQL = "select sum(维修费用) from 维护维修表 where 维修时间>'" & CDate(FirstDay) - 31 & "'and 维修时间<'" & FirstDay & "'"
Debug.Print txtSQL
conn.Execute txtSQL
rs.Open txtSQL, conn, adOpenStatic, adLockOptimistic
End Sub
是为了统计上个月维修费用的总和.
这样统计有些可能不够准确,有什么别的好方法吗?