Date Issue...

doran_doran

Registered User.
Local time
Yesterday, 20:37
Joined
Aug 15, 2002
Messages
349
I am using following code to validate Invoice Date on my form.

Rules:
1. End user is not allow to put a date that is less than todays date.
2. Invoice date must be the 25th of a month

So, If I am entering Invoice data today (04/27/2004), and I put an Invoice date "04/20/2004", then I should get an error msg. If I put an Invoice date "04/25/2004", then I should get an error msg. If I put an Invoice date "05/14/2004", then I should get an msg that Invoice date must be 25th of a month.

I am using following code and is not working.
=========================================================
If Me.txtInvoiceDate < Now And Not IsDate(DateSerial(1, Month(25), 1)) Then
MsgBox "Invoice Date must be greater than today's date and it's 25th day of the month. ", vbExclamation, "WARNING"
End If
=========================================================

Best Regards
Dianna
 
Private Sub DteTo_BeforeUpdate(Cancel As Integer)
If (Me.DteTo < Date And Day(Me.DteTo) <> 25) Then
MsgBox "Date is Too Early and not the 25th"
ElseIf Me.DteTo < Date Then
MsgBox "DateTooEarly"
ElseIf Day(Me.DteTo) <> 25 Then
MsgBox "Date is not the 25th!"


End If



End Sub
 
Glitch.....

Thanks Rich for your prompt respond. However, why am I still getting error.

Private Sub txtInvoiceBillDate_BeforeUpdate(Cancel As Integer)
If (Me.txtInvoiceBillDate < Date And Day(Me.txtInvoiceBillDate) <> 25) Then
MsgBox "Date is Too Early and not the 25th"
Day(Me.txtInvoiceBillDate) = 25 ' this should changes the day to 25th
Me.txtInvoiceBillDate.SetFocus
ElseIf Me.txtInvoiceBillDate < Date Then
MsgBox "Date is Too Early"
Me.txtInvoiceBillDate.SetFocus
ElseIf Day(Me.txtInvoiceBillDate) <> 25 Then
MsgBox "Date is not the 25th!"
Day(Me.txtInvoiceBillDate) = 25
Me.txtInvoiceBillDate.Undo
Me.txtInvoiceBillDate.SetFocus
End If

End Sub
 
I doubt you can just correct the Day part of an entered Date field. Better to use Cancel=True and Undo
 
before update...

I deleted the day portion. Why then the setfocus is not working.
 
Can Someone Verify my Code Please...

I am getting an Application Error, followed by Crash

Please help.
======================================================
Private Sub txtInvoiceBillDate_BeforeUpdate(Cancel As Integer)
If (Me.txtInvoiceBillDate < Date And Day(Me.txtInvoiceBillDate) <> 25) Then
MsgBox "Date is Too Early and not the 25th"
'Day(Me.txtInvoiceBillDate) = 25
Me.txtInvoiceBillDate.Undo
Me.txtInvoiceBillDate.SetFocus
ElseIf Me.txtInvoiceBillDate < Date Then
MsgBox "Date is Too Early"
Me.txtInvoiceBillDate.Undo
Me.txtInvoiceBillDate.SetFocus
ElseIf Day(Me.txtInvoiceBillDate) <> 25 Then
MsgBox "Date is not the 25th!"
'Day(Me.txtInvoiceBillDate) = 25
' Me.txtInvoiceBillDate.Undo
'Cancel = True
DoCmd.CancelEvent
Me.txtInvoiceBillDate.SetFocus
End If

'Cancel = True

End Sub
 
Private Sub txtInvoiceBillDate_BeforeUpdate(Cancel As Integer)
If (Me.txtInvoiceBillDate < Date And Day(Me.txtInvoiceBillDate) <> 25) Then
MsgBox "Date is Too Early and not the 25th"
Cancel=True
txtInvoiceBillDate.Undo
ElseIf Me.txtInvoiceBillDate < Date Then
MsgBox "Date is Too Early"
Cancel=True
txtInvoiceBillDate.Undo
ElseIf Day(Me.txtInvoiceBillDate) <> 25 Then
MsgBox "Date is not the 25th!"
Cancel=True
txtInvoiceBillDate.Undo
End If
 
It worked...

Thanks Rich for being patience with me and fixing the code again and again.

Thanks a Bunch

Dianna

The following code changes the day as well....
Code begins here
==========================================================
Private Sub txtInvoiceBillDate_AfterUpdate()
Dim vTempDate As Variant

Select Case Day(Date)
Case Is <= 25
If CDate(Me.txtInvoiceBillDate) <= Date Then
Me.txtInvoiceBillDate = CDate(Month(Date) & "/25/" & Year(Date))
Else
Me.txtInvoiceBillDate = CDate(Month(Me.txtInvoiceBillDate) & "/25/" & Year(Me.txtInvoiceBillDate))
End If
Case Is > 25
vTempDate = DateAdd("m", 1, Date)
If CDate(Me.txtInvoiceBillDate) <= Date Then
Me.txtInvoiceBillDate = CDate(Month(vTempDate) & "/25/" & Year(vTempDate))
Else
If Month(Me.txtInvoiceBillDate) = Month(Date) Then
Me.txtInvoiceBillDate = CDate(Month(vTempDate) & "/25/" & Year(vTempDate))
Else
Me.txtInvoiceBillDate = CDate(Month(Me.txtInvoiceBillDate) & "/25/" & Year(Me.txtInvoiceBillDate))
End If
End If
End Select

End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom