calendar help

  • Thread starter Thread starter Clay Forbes
  • Start date Start date
C

Clay Forbes

I have two calendars on my form. How can i make it so when the user
presses a command button it checks to see if the first calendar date
is greater than the second and if it is a message box appears?
 
Clay,

I'll assume below the two calendars are called cldrFrom and cldrTo
respectively, and you'll have to cahnge to the real names.
The following code must be pasted in the On Click event of the command
button:

If Me.cldrFrom > Me.cldrTo Then
strTitle = "Date range error!"
strMessage = "The selected start date is later than the selected end
date."
msgbox strMessage, vbCritical,strTitle
End If

HTH,
Nikos
 
Nikos,
When i compiled that code there were no errors, but unfortunately when
i tried to click on the command button a microsoft access error came
up telling me that i cannot reference a control unless it is in focus.
What should i do to get that to go away?
 
Clay,

The snippet of code I gave you is very unlikely to have produced this error,
chances are it is coming from another line in your code. When you get the
error message, click Debug and Access will highlight the line of code
producing the error in the VB window, which is a good start.
Now, in my experience, this kind of error ususally occurs when you reference
a control's Text or Value property while it does not have the focus. Look
for a reference like Me.SomeControl.Text or Me.SomeControl.Value. If this is
indeed the case, just wipe out the last part of the reference, and use just
Me.SomeControl instead, which by default refernces a conrtrol's value
property.
If this is not the case and you still need help, repost with your code and
indicate the line the error occurs on.

HTH,
Nikos
 
Back
Top