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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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
 
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
 
thanks for help Spitz
i tried it. it gave me the message but also accepted a wrong date after
loosing focus
any more ideas ?
 
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
 
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?
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top