我正在尝试创建一个查询,当我提供范围为Min和Max时,该查询可以在一个字段中为我提供数字列表。 E.g最小= 30 最大= 35 结果:30,31,32,33,34,35
结果应该在一个字段中。
Farrukh Khan
答案 0 :(得分:2)
我认为古斯塔夫提供的答案是一个开始。这就是它需要如何修改才能得到你需要的东西。
首先,在标准模块中创建VBA用户定义函数。像这样,
Public Function ListOfNumbers(FirstValue As Long, LastValue As Long) As String
Dim Index As Integer, tmpStr As String
If LastValue < FirstValue Then
ListOfNumbers = vbNullString
Exit Function
End If
For Index = FirstValue To LastValue
tmpStr = tmpStr & Index & ", "
Next
ListOfNumbers = Left(tmpStr, Len(tmpStr) - 2)
End Function
请记住模块名称 不应 与功能名称相同。那么SQL就像是,
PARAMETERS
MinVal Long,
MaxVal Long;
SELECT
ListOfNumbers(MinVal, MaxVal);
答案 1 :(得分:0)
您可以使用以下功能:
Public Function ListOfNumbers(ByVal FirstValue As Integer, ByVal LastValue As Integer) As String
Dim NumberList() As String
Dim Index As Integer
ReDim NumberList(FirstValue To LastValue)
For Index = FirstValue To LastValue
NumberList(Index) = CStr(Index)
Next
ListOfNumbers = Join(NumberList, ",")
End Function