我正在使用表单创建发票("frmInvoices")。由于人们有时会为下个月的发票发送预付款,我记录了三个字段;"frmInvoices"上的"预付款金额"、"预付款月份"one_answers"预付款年份"。我也希望将这些数据放在"tblPrapayment"表上。
踢球者。为了使我的系统正常工作,我需要确保在保存发票表格并输入预付款价值时,也输入该月份和年份。
我已将此代码放置在我的Microsoft Access类对象中,而不是模块中。我只需要这个来处理"frmInvoices"表单。我没有任何错误。但也没有什么真正的事情发生。如果你知道一种更简单的方法,我也愿意接受。
Private Sub Add_Prepayment_Save()
DoCmd.Save ("frmInvoices")
If [Rec'd_Prepayment] = "$0.00" Then
DoCmd.Save ("frmInvoices")
End If
If [Rec'd_Prepayments] <> "$0.00" And [Prepayment_Month] = "" Or [Prepayment_Year] = "" Then
MsgBox "Please Update Prepayment Month And/Or Prepayment Year"
End If
If [Rec'd_Prepayments] <> "0.00" And [Prepayment_Month] <> "" Or [Prepayment_Year] <> "" Then
Dim RecSet As Recordset
Set RecSet = CurrentDb.OpenRecordset("tblPrePayments")
RecSet.AddNew
RecSet![AccountID] = "AccountID"
RecSet![Prepayment_Month] = "Billing_Month"
RecSet![Prepayment_Year] = "Billing_Year"
RecSet![Rec'd_Prepayment] = "Prepayment1"
RecSet.Update
End If
End Sub
尝试将其添加到表单模块中:
Private Sub Form_AfterUpdate()
MsgBox "Time to validate the form!" ''reassurance, temp
Call Add_Prepayment_Save
End Sub
您可能希望使Add_Prepayment_Save
成为一个返回True或False的函数。如果用户需要在表单上做更多的工作,函数将返回false,然后您从那里进行处理。我通常需要花点时间——例如,从Form_Close
或Form_LostFocus
调用验证可能比Form_AfterUpdate()
更好。