By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,379 Members | 3,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,379 IT Pros & Developers. It's quick & easy.

calendar

P: 77
i have three fields where a date needs to be entered..

i have a calendar so when user clicks the field then the user can choose date from calendar and that will be enetered..

what i need is when the user enters date in field 1 then when he chooses date for field 2 the date will have to be after the date in field 1 and msg showing "please choose date after (what ever date is in field 1)"

can anyone help
Mar 19 '07 #1
Share this Question
Share on Google+
7 Replies


missinglinq
Expert 2.5K+
P: 3,532
Where Date1 textbox holds first date and Date2 textbox holds the second date:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Date2_BeforeUpdate(Cancel As Integer)
  2.   If Me.Date1 >= Me.Date2 Then
  3.     Message = "Please Choose Date After " & Me.Date1 & "!"
  4.     MsgBox (Message)
  5.   End If
  6. End Sub
Mar 19 '07 #2

P: 77
i already have the following code for the calendar...

Private Sub Calendar5_Click()
Rental_Out.Value = Calendar5.Value
Rental_Out.SetFocus
Calendar5.Visible = False

End Sub


Private Sub Calendar6_Click()
Rental_Due.Value = Calendar6.Value
Rental_Due.SetFocus
Calendar6.Visible = False

End Sub


Private Sub Calendar7_Click()
Rental_Returned.Value = Calendar7.Value
Rental_Returned.SetFocus
Calendar7.Visible = False

End Sub


Private Sub Rental_Due_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Calendar6.Visible = True
Calendar6.SetFocus
If Not IsNull(Rental_Due) Then
Calendar6.Value = Rental_Due.Value
Else
Calendar6.Value = Date
End If

End Sub


Private Sub Rental_Out_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Calendar5.Visible = True
Calendar5.SetFocus
If Not IsNull(Rental_Out) Then
Calendar5.Value = Rental_Out.Value
Else
Calendar5.Value = Date
End If

End Sub

Private Sub Rental_Returned_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Calendar7.Visible = True
Calendar7.SetFocus
If Not IsNull(Rental_Returned) Then
Calendar7.Value = Rental_Returned.Value
Else
Calendar7.Value = Date
End If

End Sub


this code allows to enter in 3 dates in 3 fields...where do i implement the msg code...??
Mar 19 '07 #3

missinglinq
Expert 2.5K+
P: 3,532
what i need is when the user enters date in field 1 then when he chooses date for field 2 the date will have to be after the date in field 1 and msg showing "please choose date after (what ever date is in field 1)"
The code goes in the BeforeUpdate event of the textbox that holds field 2, whatever that "field" is named.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Date2_BeforeUpdate(Cancel As Integer)
  2.   If Me.Date1 >= Me.Date2 Then
  3.     Message = "Please Choose Date After " & Me.Date1 & "!"
  4.     MsgBox (Message)
  5.   End If
  6. End Sub
Replace Date2 in the code with the actual name of your "field 2."
Mar 19 '07 #4

P: 77
The code goes in the BeforeUpdate event of the textbox that holds field 2, whatever that "field" is named.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Date2_BeforeUpdate(Cancel As Integer)
  2.   If Me.Date1 >= Me.Date2 Then
  3.     Message = "Please Choose Date After " & Me.Date1 & "!"
  4.     MsgBox (Message)
  5.   End If
  6. End Sub
Replace Date2 in the code with the actual name of your "field 2."

thanx i got it working
Mar 21 '07 #5

P: 77
thanx i got it working

when i click on the date 2 i get the msg but the calendar still allows me to enter a date before the date 1.. how do i restrict that and only allow dates after date 1??
Mar 21 '07 #6

missinglinq
Expert 2.5K+
P: 3,532
Try adding Cancel = True
Expand|Select|Wrap|Line Numbers
  1. Private Sub Date2_BeforeUpdate(Cancel As Integer)
  2.   If Me.Date1 >= Me.Date2 Then
  3.     Message = "Please Choose Date After " & Me.Date1 & "!"
  4.     MsgBox (Message)
  5.         Cancel = True  
  6.   End If
  7. End Sub
Mar 21 '07 #7

P: 77
Try adding Cancel = True
Expand|Select|Wrap|Line Numbers
  1. Private Sub Date2_BeforeUpdate(Cancel As Integer)
  2.   If Me.Date1 >= Me.Date2 Then
  3.     Message = "Please Choose Date After " & Me.Date1 & "!"
  4.     MsgBox (Message)
  5.         Cancel = True  
  6.   End If
  7. End Sub

that piece of code still allows the date to be entered
Mar 22 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.