基于Access中的数字生成范围
问题描述:
我试图让一个字段显示1和另一个字段中的数字之间的数字范围,并带有前面的标识符。 例如,当标记为“TotalQuestions”的字段的值为“5”时,我希望另一个字段(例如“TableInfo”)由“Question1,Question2,Question3,Question4,Question5”填充。基于Access中的数字生成范围
答
的VBA函数
Public Function GenerateRepeatedText(maxNumber As Long) As String
Const PrefixText = "Question"
Const SeparatorText = ", "
Dim i As Long, rtn As String
rtn = ""
For i = 1 To maxNumber
rtn = rtn & PrefixText & i & SeparatorText
Next
If Len(rtn) > 0 Then
'' trim trailing separator
rtn = Left(rtn, Len(rtn) - Len(SeparatorText))
End If
GenerateRepeatedText = rtn
End Function
可以在查询中使用这样的:
SELECT TotalQuestions, GenerateRepeatedText([TotalQuestions]) AS TableInfo FROM ...
谢谢!这很好! – James
我建议接受答案,如果他们是正确的。否则,人们未来可能不太愿意帮助你。只是我的想法:) – Chris