Comparison in date

  • Thread starter EMILYTAN via AccessMonster.com
  • Start date
E

EMILYTAN via AccessMonster.com

Below is my code. It simply can't run.

Private Sub cboDateExpired_BeforeUpdate(Cancel As Integer)
Dim date1, date2 As Date
date1 = Me!DateExpired
date2 = Me!DateLoan
If (date1 < date2) Then
MsgBox "The Date Expired is in wrong value!"
End If
End Sub
 
R

Rob Parker

"It simply can't run" is not very helpful. What does happen? Do you get
any error message? Maybe it is running, but not doing what you were
expecting. And that might be because date1 is not declared as a Date
variable. You must explicitly declare the type of each variable, so you
need:

Dim date1 As Date, date2 As Date

HTH,

Rob
 
E

EMILYTAN via AccessMonster.com

I change it also cannot...
It didnt reponse anything nor give any error message...

Rob said:
"It simply can't run" is not very helpful. What does happen? Do you get
any error message? Maybe it is running, but not doing what you were
expecting. And that might be because date1 is not declared as a Date
variable. You must explicitly declare the type of each variable, so you
need:

Dim date1 As Date, date2 As Date

HTH,

Rob
Below is my code. It simply can't run.
[quoted text clipped - 6 lines]
End If
End Sub
 
R

Rob Parker

How do you know it's not running?

Have you set a breakpoint in the routine, and tried stepping through the
code a line at a time,and seeing what values your variables actually
contain, and whether the If condition is true for your data, so that your
message box will be displayed?

Rob

EMILYTAN via AccessMonster.com said:
I change it also cannot...
It didnt reponse anything nor give any error message...

Rob said:
"It simply can't run" is not very helpful. What does happen? Do you get
any error message? Maybe it is running, but not doing what you were
expecting. And that might be because date1 is not declared as a Date
variable. You must explicitly declare the type of each variable, so you
need:

Dim date1 As Date, date2 As Date

HTH,

Rob
Below is my code. It simply can't run.
[quoted text clipped - 6 lines]
End If
End Sub
 
E

EMILYTAN via AccessMonster.com

I tried to put in the wrong data but it cannot run also...
My messagebox didnt appear...
My idea is when once that user key in wrong date, I want the message box to
appear but it didnt show anything...

Rob said:
How do you know it's not running?

Have you set a breakpoint in the routine, and tried stepping through the
code a line at a time,and seeing what values your variables actually
contain, and whether the If condition is true for your data, so that your
message box will be displayed?

Rob
I change it also cannot...
It didnt reponse anything nor give any error message...
[quoted text clipped - 16 lines]
 
R

Rob Parker

Again, all I can suggest at this time is to set a breakpoint in your code,
and see exactly what is happening. Do you know how to do that, and step
through the code? If so, what happens? Are the values of your variables
what you expect them to be? Does your If statement evaluate as you expect
it to?

Rob

EMILYTAN via AccessMonster.com said:
I tried to put in the wrong data but it cannot run also...
My messagebox didnt appear...
My idea is when once that user key in wrong date, I want the message box
to
appear but it didnt show anything...

Rob said:
How do you know it's not running?

Have you set a breakpoint in the routine, and tried stepping through the
code a line at a time,and seeing what values your variables actually
contain, and whether the If condition is true for your data, so that your
message box will be displayed?

Rob
I change it also cannot...
It didnt reponse anything nor give any error message...
[quoted text clipped - 16 lines]
End If
End Sub
 

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

Top