我在Access VBA中有以下功能
Sub SampleReadCurve()
Dim rs As Recordset
Dim iRow As Long, iField As Long
Dim strSQL As String
Dim CurveID As Long
Dim MarkRunID As Long
Dim MaxOfMarkAsofDate As Date
Dim userdate As String
CurveID = 15
Dim I As Integer
Dim x As Date
userdate = InputBox("Please Enter the Date (mm/dd/yyyy)")
x = userdate
For I = 0 To 150
MaxOfMarkAsofDate = x - I
strSQL = "SELECT * FROM VolatilityOutput WHERE CurveID=" & CurveID & " AND MaxOfMarkAsofDate=#" & MaxOfMarkAsofDate & "# ORDER BY MaxOfMarkasOfDate, MaturityDate"
Set rs = CurrentDb.OpenRecordset(strSQL, Type:=dbOpenDynaset, Options:=dbSeeChanges)
If rs.RecordCount <> 0 Then
rs.MoveFirst
rs.MoveLast
Dim BucketTermAmt As Long
Dim BucketTermUnit As String
Dim BucketDate As Date
Dim MarkAsOfDate As Date
Dim InterpRate As Double
BucketTermAmt = 3
BucketTermUnit = "m"
BucketDate = DateAdd(BucketTermUnit, BucketTermAmt, MaxOfMarkAsofDate)
InterpRate = CurveInterpolateRecordset(rs, BucketDate)
Debug.Print BucketDate, InterpRate
End If
Next I
End Sub
运行此子项会在即时窗口中输出一个数字列表和相关日期,格式为:
10/21/2015 4.14783100557042E-03
10/20/2015 3.97301001744437E-03
10/17/2015 4.26331322736052E-03
10/16/2015 4.04793424134467E-03
...
现在,我想使用这个数字数组作为函数的输入。这样做需要我保存子程序的输出。解决这个问题的最佳方式是什么?我想将它保存为RecordSet对象,但我不知道如何做到这一点。
答案 0 :(得分:1)
返回记录集作为函数的结果而不是过程,例如:
Function SampleReadCurve() As Recordset
'Complete database action and load recordset into variable called rs'
SampleReadCurve = rs
End Function
然后您可以将记录集作为另一个过程中的变量返回。