calendar control+before update+HELP

I

Ivan Palèiæ

Hi,

I have a little problem with the code below. I want that i can't input
EndDate that is before StartDate by clicking it on the CalendarControl, but
it doesn't work. I tried everything. Help me out, please!

Thanks in advance

_______________________________________

Option Compare Database

Option Explicit

Dim coordinator As ComboBox



Private Sub Calendar9_Click()

coordinator.Value = Calendar9.Value

coordinator.SetFocus

Calendar9.Visible = False

Set coordinator = Nothing

End Sub



Private Sub StartDate_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)

Set coordinator = StartDate

Calendar9.Visible = True

Calendar9.SetFocus

If Not IsNull(coordinator) Then

Calendar9.Value = coordinator.Value

Else

Calendar9.Value = Date

End If

End Sub



Private Sub EndDate_GotFocus(Cancel As Integer)

If EndDate < StartDate Then

Cancel = True

MsgBox "EndDate can't be before StartDate", vbCritical + vbOKOnly,
"Warning!"

End If

If EndDate = StartDate Then

Cancel = True

MsgBox "Guest didn't sleep over the night!", vbCritical + vbOKOnly,
"Warning!"

End If

End Sub





Private Sub EndDate_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)

Set coordinator = EndDate

Calendar9.Visible = True

Calendar9.SetFocus

If Not IsNull(coordinator) Then

Calendar9.Value = coordinator.Value

Else

Calendar9.Value = Date

End If

End Sub
 
M

Michael.Keating

Hi,

You seem to be checking the end date value when that textbox gets the focus
but the user hasn't put any information in there yet.

Try changing the calendar click event to test the end date, something like:

Private Sub Calendar9_Click()

If (coordinator IS EndDate) And (Calendar9.Value <= StartDate) Then

Msgbox "Error Message"
Exit Sub
End If

coordinator.Value = Calendar9.Value

coordinator.SetFocus

Calendar9.Visible = False

Set coordinator = Nothing
End Sub

HTH

MFK.
 

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

Similar Threads


Top