将先前的fieldvalue分配给下一条记录中的字段

时间:2013-11-02 02:20:46

标签: forms vba ms-access

我正在使用Access制定贷款摊还计划,我创建了以下表格:

tblMembers - autoMemberID|txtLN|txtFN|etc
tblLoans - autoLoanID|numMemberID|etc
tblSchedules -autoScheduleID|numLoanID|numPayment#|datDue|dblBegin|...|dblEnd
tblPayments - autoPaymID|numLoanID|curAmtPaid|datPaidDate

和表格:

frmLoans - autoLoanID|etc
sbfSchedules - numPaymID|datDue|dblBegin|...|dblEnd
sbfPayments - dblAmount|datPaid

我已经能够生成时间表(使用DAO recordset)点击btnRepaymentSchedule挑战是当我点击btnAddPayment上的sbfSchedules时,我希望dblEnd字段的值为下一个记录dblBegin字段的值!我尝试过使用

dlookup(txtBeginBalance = Dlookup("EndBalance", _
    "Schedules","[ScheduleID] = Form![Schedules]![ScheduleID]-1) 

但是如果我使用

则没有效果
txtBeginBalance = txtEndBalance 

txtEndBalance的值分配给同一记录的txtBeginBalance值(想要下一条记录)。

其次,如果contro(txtAmountPaid)在单击btnAddPayment时不为空,或者在控件为0或为空时指定计算值,如何将焦点设置为下一条记录?

由于

1 个答案:

答案 0 :(得分:0)

您是否尝试过记录集而不是(慢得多)dlookup?有点像...

     Dim rs As DAO.Recordset
     Set rs = CurrentDb.OpenRecordset("select [EndBalance] from [Schedules] where [ScheduleID] = " & Form!Schedules!ScheduleID - 1)
     If Not rs.EOF Then
         Forms!Schedules!DblBegin = rs!EndBalance
     End If
     rs.Close
     Set rs = Nothing

...第二个q:

    If Not IsNull(Forms!Schedules!txtAmountPaid) then
            DoCmd.GoToRecord , , acNext 
    Else
            Forms!Schedules!Your_Field_Name = calculation_goes_here
    End If