标题: 请帮助看看这种动态条件查询如何做? [打印本页] 作者: yanwei82123300 时间: 2009-4-1 11:23 标题: 请帮助看看这种动态条件查询如何做? 请帮助看看这种动态条件查询如何做
我在窗体Totaldemand中的demand文本框中输入一个条件 例如:=[200923]+[200924]+[200925]后
在查询qryTotaldemand的total字段自动将结果算出
请问如何做?谢谢作者: Henry D. Sy 时间: 2009-4-1 11:33
demand文本框在那里??作者: yanwei82123300 时间: 2009-4-1 12:07
在窗体中,标签名为total作者: Henry D. Sy 时间: 2009-4-1 12:12
Dim strArray() As String
Dim strTemp As String
Dim strSQL As String
Dim Qdf As DAO.QueryDef
Dim i As Integer
If IsNull(Me.demand) Then Exit Sub
strArray = Split(Me.demand, "+")
For i = 0 To UBound(strArray)
strTemp = strTemp & "Nz(" & strArray(i) & ")+"
Next
strTemp = Left(strTemp, Len(strTemp) - 1)
strSQL = "SELECT Table1.*, " & strTemp & " AS total FROM Table1"
Set Qdf = CurrentDb.QueryDefs("qryTotaldemand")
Qdf.SQL = strSQL
Qdf.Close
Set Qdf = Nothing
Me.RecordSource = "qryTotaldemand"作者: yanwei82123300 时间: 2009-4-1 12:30
老师请问是输入格式或方法Nz([200924])+Nz([200925])+Nz([200926])吗有没有办法直接输入200924 +20025+200926格式自动添加的?作者: Henry D. Sy 时间: 2009-4-1 13:05
Dim strArray() As String
Dim strTemp As String
Dim strSQL As String
Dim Qdf As DAO.QueryDef
Dim i As Integer
If IsNull(Me.demand) Then Exit Sub
strArray = Split(Me.demand, "+")
For i = 0 To UBound(strArray)
strTemp = strTemp & "Nz([" & strArray(i) & "])+"
Next
strTemp = Left(strTemp, Len(strTemp) - 1)
strSQL = "SELECT Table1.*, " & strTemp & " AS total FROM Table1"
Set Qdf = CurrentDb.QueryDefs("qryTotaldemand")
Qdf.SQL = strSQL
Qdf.Close
Set Qdf = Nothing
Me.RecordSource = "qryTotaldemand"
复制代码
直接输入200922+200923作者: yanwei82123300 时间: 2009-4-1 13:09
thank you teacher help me作者: yanwei82123300 时间: 2009-4-5 15:10
6d老师:
我还有一个问题:想在Totaldemand中的demand文本框中输入一个条件:200923 to 200927
怎样编写?
谢谢作者: Henry D. Sy 时间: 2009-4-5 16:47
6d老师:
我还有一个问题:想在Totaldemand中的demand文本框中输入一个条件:200923 to 200927
怎样编写?
谢谢
yanwei82123300 发表于 2009-4-5 15:10
Private Sub demand_AfterUpdate()
Dim strArray() As String
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
strArray = Split(Me.demand, "to")
BeginVal = Val(strArray(0))
EndVal = Val(strArray(UBound(strArray)))
For i = BeginVal To EndVal
strTemp = strTemp & "Nz([" & i & "])+"
Next
strTemp = Left(strTemp, Len(strTemp) - 1)
strSQL = "SELECT Table1.*, " & strTemp & " AS total FROM Table1"
Set Qdf = CurrentDb.QueryDefs("qryTotaldemand")
Qdf.SQL = strSQL
Qdf.Close
Set Qdf = Nothing
Me.RecordSource = "qryTotaldemand"
End Sub
复制代码
作者: 阿六爱狗 时间: 2009-4-6 16:35
学习了作者: yanwei82123300 时间: 2009-4-7 07:48
谢谢6d老师作者: Henry D. Sy 时间: 2009-4-7 08:01
简单点,可以用left,right函数,不用数组。作者: Henry D. Sy 时间: 2009-4-7 08:08
Private Sub demand_AfterUpdate()
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 Table1.*, " & strTemp & " AS total FROM Table1"