how to limit date entery in field to value not >9m from another

E

el-hawi

I need to limit date entry to a value not more than 9 months later than
another date field in the same form. I tried many options but they didn't
work. can more experienced one tell me how?
 
G

Granny Spitz via AccessMonster.com

el-hawi said:
I need to limit date entry to a value not more than 9 months later than
another date field in the same form.

If the text box you want to limit is named txtEndDate and it's compared to
the date in txtStartDate, you can put this code in the txtEndDate's before
update event:

Private Sub txtEndDate_BeforeUpdate(Cancel As Integer)
If (DateAdd("m", 9, Me!txtStartDate.Value) < Me!txtEndDate.Value) Then
Cancel = True
MsgBox "The end date must not be more than 9 months after the start
date."
End If
End Sub
 
F

fredg

I need to limit date entry to a value not more than 9 months later than
another date field in the same form. I tried many options but they didn't
work. can more experienced one tell me how?

Code the BeforeUpdate event of the control:
If DateAdd("m",9,[ThisControl]) > Me![ThatControl] Then
MsgBox "You must enter a date less than 9 months from " &
[ThatContro;]
Cancel = True
End If
 
E

el-hawi

thanks for help Spitz
i tried it. it gave me the message but also accepted a wrong date after
loosing focus
any more ideas ?
 
E

el-hawi

thanks for help fredg
i tried it. it gave me the message but also accepted a wrong date after
loosing focus
any more ideas ?


fredg said:
I need to limit date entry to a value not more than 9 months later than
another date field in the same form. I tried many options but they didn't
work. can more experienced one tell me how?

Code the BeforeUpdate event of the control:
If DateAdd("m",9,[ThisControl]) > Me![ThatControl] Then
MsgBox "You must enter a date less than 9 months from " &
[ThatContro;]
Cancel = True
End If
 
G

Granny Spitz via AccessMonster.com

el-hawi said:
it gave me the message but also accepted a wrong date after
loosing focus

Are both text boxes date data types and "required"? What date is in the
start date text box and what date is in the end date text box when it accepts
the wrong date?
 
E

el-hawi

dear Mr spitz
thanks for cooperation. as regards yout questions
1- data type id Date & format is mmm/yyyy for both text boxes
2- these fields properties don't contain this property "required" or not
item. however, in the related table both fields are not required.
thanks
ezzat el-hawi
 
Top