我是一个老 Foxpro 程序员,我曾经使用数组来发布变量字段。
我想要做的是我设计的新表中有 15 个日期字段。
在我的查询中,我有一个活动日期的个人记录。
我想将每个日期的 15 个不同日期编译为Client_id
一个包含 15 个日期的记录,但我似乎无法将表数据作为数组引用。
我尝试了几种不同的方法来定义数组,但似乎没有任何效果。
这是我的代码。在我的表中,我有 15 个名为Mail_date1
, Mail_date2
,Mail_date3
等的日期字段。
我首先尝试将它定义为一个数组,但不喜欢它;当我尝试引用结果表中的日期字段时,我的代码总是失败rs2!mdate2 = memdate(intcounter)
如何将我的结果表输出字段作为数组引用?
我是否必须放置一大堆 if 语句来加载我的结果?
似乎很浪费......应该能够将它们作为数组加载。
我是一个新的 Access 2007 VBA 程序员。
Dim db As DAO.Database
Set db = CurrentDb
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim FinTotal, intcounter As Integer
Dim FinMPU, FinVersion As String
Dim mail_date(1 To 15) As Date
Dim memdate(1 To 15) As Date
Dim mdate2 As String
Set rs1 = db.OpenRecordset( _
"SELECT NewFile.MPU_ID, " & _
" NewFile.MAIL_DATE," & _
" NewFile.TOTAL, " & _
" Freight.Version " &_
"FROM Freight " & _
" LEFT JOIN NewFile ON Freight.[MPU ID] = NewFile.MPU_ID " & _
"ORDER BY NewFile.MPU_ID, NewFile.MAIL_DATE")
Set rs2 = db.OpenRecordset("Final")
DoCmd.RunSQL "DELETE Final.* FROM Final;"
intcounter = 1
memdate(intcounter) = rs1!mail_date
FinMPU = rs1!mpu_ID
FinTotal = rs1!total
FinVersion = rs1!Version
rs1.MoveNext
On Error GoTo Error_MayCauseAnError
Do While Not rs1.EOF
Do While Not rs1.EOF _
And memdate(intcounter) <> rs1!mail_date _
And FinMPU = rs1!mpu_ID
intcounter = intcounter + 1
memdate(intcounter) = rs1!mail_date
FinTotal = FinTotal + rs1!total
FinVersion = rs1!Version
FinMPU = rs1!mpu_ID
rs1.MoveNext
Loop
If FinMPU <> rs1!mpu_ID Then
rs2.AddNew
mdate2 = "mail_date" & CStr(intcounter)
rs2!mdate2 = memdate(intcounter)
rs2!total = FinTotal
rs2!mpu_ID = FinMPU
rs2!Version = FinVersion
rs2.Update
FinTotal = rs1!total
FinVersion = rs1!Version
FinMPU = rs1!mpu_ID
intcounter = 1
memdate(intcounter) = rs1!mail_date
End If
rs1.MoveNext
Loop