Office中国论坛/Access中国论坛

标题: 对动态字符串求和 [打印本页]

作者: yanwei82123300    时间: 2010-3-18 15:13
标题: 对动态字符串求和
下面的代码是6D老师帮助做的,现在请大家帮助修改一下:下面的代码中Val(Left(Me.demand, 6));EndVal = Val(Right(Me.demand, 6))
    For i = BeginVal To EndVal
strTemp = strTemp & "Nz([" & i & "])+"
为在字符串中取数字,并进行求和能否改为直接取字符串,并对字符串就和因为里面的(原来字符串为201029)现在为2009W02
谢谢
Dim strTemp As String
    Dim strSQL As String
    Dim Qdf As DAO.QueryDef
    Dim i As Long
    Dim BeginVal As Long, EndVal As Long
    If IsNull(Me.demand) Then Exit Sub
    BeginVal = Val(Left(Me.demand, 6))
    EndVal = Val(Right(Me.demand, 6))
    For i = BeginVal To EndVal
        strTemp = strTemp & "Nz([" & i & "])+"
    Next
    strTemp = Left(strTemp, Len(strTemp) - 1)
    strSQL = "SELECT tbl67CFRDemand.*, " & strTemp & " AS total FROM tbl67CFRDemand"
    Set Qdf = CurrentDb.QueryDefs("qry67CFRDemandtbl")
    Qdf.SQL = strSQL
    Qdf.Close
    Set Qdf = Nothing
    Me.RecordSource = "qry67CFRDemandtbl"
        
Me.sub67CFR_Detail.Requery
Me.sub67CFR_Detail.Form.RecordSource = "qry67CFRDemand_temp2"
End Sub




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3