update checkbox when date greater than current.

G

Guest

Thought this would be easy:
I want a checkbox (Active) to be set to -1 (YES) if the date entered in a
textbox (CallDate) is greater than today. Code compiles and doesn't show any
errors but doesn't work either. Also tried 'Me!CallDate > GetDate()' and '>
Date'

Private Sub CallDate_Change()
If Me!CallDate > Now() Then
Me![Active] = -1
End If
End Sub
 
A

Al Campagna

Ian,
Use the AfterUpdate event of CallDate, not Change. Change fires your code on every
character entry... AfterUpdate after the entire value has been entered in the control.
And a minor point... if CallDate is really just a Date, with no Time, it would be best
(clearer) to use CallDate > Date. But Now won't cause a problem...
Private Sub CallDate_AfterUpdate()
If Me!CallDate > Now() Then
Me![Active] = -1
End If
End Sub
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
Ian said:
Thought this would be easy:
I want a checkbox (Active) to be set to -1 (YES) if the date entered in a
textbox (CallDate) is greater than today. Code compiles and doesn't show any
errors but doesn't work either. Also tried 'Me!CallDate > GetDate()' and '>
Date'

Private Sub CallDate_Change()
If Me!CallDate > Now() Then
Me![Active] = -1
End If
End Sub
 
A

Al Campagna

Ian,
One other point...
It might be best to add an Else statement to your code, in case CallDate is ever
re-edited... (your call)
Private Sub CallDate_AfterUpdate()
If Me!CallDate > Now() Then
Me![Active] = -1
Else
Me![Active] = 0
End If
End Sub
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."

Ian said:
Thought this would be easy:
I want a checkbox (Active) to be set to -1 (YES) if the date entered in a
textbox (CallDate) is greater than today. Code compiles and doesn't show any
errors but doesn't work either. Also tried 'Me!CallDate > GetDate()' and '>
Date'

Private Sub CallDate_Change()
If Me!CallDate > Now() Then
Me![Active] = -1
End If
End Sub
 
G

Guest

Still nothing. The only thing I can think is that there is a pop-up calender
coded into the combobox calldate. Here is the code that places the Calender
choice into the datefield.

Private Sub CallDate_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Set cboOriginator = CallDate
Calendar3.Visible = True
Calendar3.SetFocus
If Not IsNull(cboOriginator) Then
Calendar3.Value = cboOriginator.Value
Else
Calendar3.Value = Date
End If
End Sub

Al Campagna said:
Ian,
One other point...
It might be best to add an Else statement to your code, in case CallDate is ever
re-edited... (your call)
Private Sub CallDate_AfterUpdate()
If Me!CallDate > Now() Then
Me![Active] = -1
Else
Me![Active] = 0
End If
End Sub
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."

Ian said:
Thought this would be easy:
I want a checkbox (Active) to be set to -1 (YES) if the date entered in a
textbox (CallDate) is greater than today. Code compiles and doesn't show any
errors but doesn't work either. Also tried 'Me!CallDate > GetDate()' and '>
Date'

Private Sub CallDate_Change()
If Me!CallDate > Now() Then
Me![Active] = -1
End If
End Sub
 
R

rwr

Ian said:
Still nothing. The only thing I can think is that there is a pop-up calender
coded into the combobox calldate. Here is the code that places the Calender
choice into the datefield.

Private Sub CallDate_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Set cboOriginator = CallDate
Calendar3.Visible = True
Calendar3.SetFocus
If Not IsNull(cboOriginator) Then
Calendar3.Value = cboOriginator.Value
Else
Calendar3.Value = Date
End If
End Sub

Al Campagna said:
Ian,
One other point...
It might be best to add an Else statement to your code, in case CallDate is ever
re-edited... (your call)
Private Sub CallDate_AfterUpdate()
If Me!CallDate > Now() Then
Me![Active] = -1
Else
Me![Active] = 0
End If
End Sub
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."

Ian said:
Thought this would be easy:
I want a checkbox (Active) to be set to -1 (YES) if the date entered in a
textbox (CallDate) is greater than today. Code compiles and doesn't show any
errors but doesn't work either. Also tried 'Me!CallDate > GetDate()' and '>
Date'

Private Sub CallDate_Change()
If Me!CallDate > Now() Then
Me![Active] = -1
End If
End Sub

Try this.

Private Sub CallDate_AfterUpdate()
dim xDate as date

xDate = Me!CallDate
If xDate > Date Then
Me![Active] = -1
Else
Me![Active] = 0
End If
End Sub


Ron
 

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