Date validation rule with popup built-in calendar

Falcon88

Registered User.
Local time
Today, 04:25
Joined
Nov 4, 2014
Messages
318
Hi dears
I have a form on it textbox for dates , it validation rule is between 01/01/2022 and 31/12/2022, i use a popup built-in calender form to select dates . But the validation rule didnot work except when user insert the date by keyboard or using the access popup calendar .

How to make that v.rule works by using that popup built-in calendar ?
 
Are you able to post a sample db to demonstrate the problem?
 
I mentioned this in my earlier video but went into more detail on the newest one which hasn't been released yet. This is just ONE of the reasons I don't use the control's BeforeUpdate event or any control events for that matter, to validate data.

You don't need to create an account to watch the video. Sorry, it's a half hour.


In summary, the control level events do NOT fire when the control is modified using VBA (or a macro). If you move the validation code to the Form's BeforeUpdate event, it will work correctly. NOTHING gets past the Form's BeforeUpdate event:)
Thanks Mr Pat Hartman .
Have you downloaded my attached file ?
 
Mr Pat

See , i use this expression on the orederdate testbox validation rule :
Code:
<DateSerial(Year(Elookup("MyDefaultDate";"tblDefaultDate";"MyDefaultDayID=1"));1;1) And >DateSerial(Year(Elookup("MyDefaultDate";"tblDefaultDate";"MyDefaultDayID=1"));12;31)

Then use this code

Code:
Option Compare Database
Option Explicit
Private Sub cmdCalendar_Click()
InputDateField OrderDate, "Select Order Date"
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ValideStDate As String
Dim ValideEnDate As String

ValideStDate = SQLDate(DateSerial(Year(ELookUp("MyDefaultDate", "tblDefaultDate", "MyDefaultDayID=1")), 1, 1))
ValideEnDate = SQLDate(DateSerial(Year(ELookUp("MyDefaultDate", "tblDefaultDate", "MyDefaultDayID=1")), 12, 31))

If Me.OrderDate < ValideStDate Then
MsgBox "AAAAAAAAA"
Cancel = True
Me.OrderDate.Undo
End If
If Me.OrderDate > ValideEnDate Then
MsgBox "zzzzzzzzzz"
Cancel = True
Me.OrderDate.Undo
End If
End Sub

Private Sub OrderDate_BeforeUpdate(Cancel As Integer)
'Dim ValideStDate As String
'Dim ValideEnDate As String
'
'ValideStDate = SQLDate(DateSerial(Year(ELookUp("MyDefaultDate", "tblDefaultDate", "MyDefaultDayID=1")), 1, 1))
'ValideEnDate = SQLDate(DateSerial(Year(ELookUp("MyDefaultDate", "tblDefaultDate", "MyDefaultDayID=1")), 12, 31))
'
'If Me.OrderDate < ValideStDate Then
'MsgBox "AAAAAAAAA"
'Cancel = True
'Me.OrderDate.Undo
'End If
'If Me.OrderDate > ValideEnDate Then
'MsgBox "zzzzzzzzzz"
'Cancel = True
'Me.OrderDate.Undo
'End If
End Sub
 
i created new frmOrder, because your old form is using Arabic control names so
i cannot make it work.
see frmOrder and the code on the button and the Orderdate.
 

Attachments

i created new frmOrder, because your old form is using Arabic control names so
i cannot make it work.
see frmOrder and the code on the button and the Orderdate.
Thanks , please reattaches this db with ms access 2007 format .
 

Users who are viewing this thread

Back
Top Bottom