A
AnhCVL via AccessMonster.com
Hi all,
I have a form consist of 3 text fied (StartDate, RecDate, and Ddays) which
bound to a data table (Dtable) for loging purpose. I want to be able to
calculate the days different between the StartDate and the RecDate and
display it on the Ddays field ( which is normally locked, manyallu entry is
not permitted). I want the form to do the calculation upon the date is
entered on the second text box ( RecDate) and displays the different on the
3rd textbox (Ddays) automatically. If the RecDate is earlier than the
StartDate, the date different will be negative value number of days (such as -
10, or -8), if the RecDate is later than the StartDate, the outcome will be
possitive value( such as 7, or 10). I was able to do it in excel by just
substract the cell ( I.E $A2-$A1, where "cell A2" acts as RecDate and "cell
A1" acts as StartDate), but failed to do so in the access form. I've tried
the DateDIff() by place the code under RecDate as below:
Private Sub RecDate_LostFocus()
Dim TDdays, StartDate, RecDate As Date
Date_Due.SetFocus
If StartDate.Text = "" Then
MsgBox "Invalid Start Date detected", vbwarning, "Input Required"
StartDate.SetFocus
ElseIf RecDate.Text = "" Then
MsgBox "Invalid Received Date detected", vbwarning, "Input
Required"
RecDate.SetFocus
Else
Ddays.Text = DateDiff("d", RecDate, StartDate)
End If
End Sub
Any suggestion?
Thanks
Mark
I have a form consist of 3 text fied (StartDate, RecDate, and Ddays) which
bound to a data table (Dtable) for loging purpose. I want to be able to
calculate the days different between the StartDate and the RecDate and
display it on the Ddays field ( which is normally locked, manyallu entry is
not permitted). I want the form to do the calculation upon the date is
entered on the second text box ( RecDate) and displays the different on the
3rd textbox (Ddays) automatically. If the RecDate is earlier than the
StartDate, the date different will be negative value number of days (such as -
10, or -8), if the RecDate is later than the StartDate, the outcome will be
possitive value( such as 7, or 10). I was able to do it in excel by just
substract the cell ( I.E $A2-$A1, where "cell A2" acts as RecDate and "cell
A1" acts as StartDate), but failed to do so in the access form. I've tried
the DateDIff() by place the code under RecDate as below:
Private Sub RecDate_LostFocus()
Dim TDdays, StartDate, RecDate As Date
Date_Due.SetFocus
If StartDate.Text = "" Then
MsgBox "Invalid Start Date detected", vbwarning, "Input Required"
StartDate.SetFocus
ElseIf RecDate.Text = "" Then
MsgBox "Invalid Received Date detected", vbwarning, "Input
Required"
RecDate.SetFocus
Else
Ddays.Text = DateDiff("d", RecDate, StartDate)
End If
End Sub
Any suggestion?
Thanks
Mark