Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign and Clear Date values with check box

Status
Not open for further replies.

JohnLanc

Technical User
May 21, 2003
17
0
0
US
I am trying to assign the current date to a field or clear the date from a field by clicking a checkbox. The problem I have is:

When I check the box I cannot get the date field to display the date (or clear it) until I click on it and the control won't allow me to use the "Setfocus" property to do this automatically.

The Code I am using:

Private Sub StepCredited_Click()
If StepCredited.Value = True Then
CreditDate.Value = Now
Else
CreditDate.Value = Null
End If
End Sub

I have tried using the requery command on the form but it say the field must be saved first!?

Any suggestions gratefully accepted!
 
I would use the AfterUpdate event of the checkbox:

Private Sub StepCredited_AfterUpdate()
If Me.StepCredited.Value = True Then
Me.CreditDate.Value = Date()
Else
Me.CreditDate.Value = Null
End If
End Sub

Let me know if that works.

Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Thanks Ben, but it still won't update the field until I click on it!

 
Got it working:

Private Sub StepCredited_click()
If StepCredited.Value = True Then
CreditDate.Value = Now
Else
CreditDate.Value = Null
End If
Me.Requery
End Sub
 
Nice one! Not sure why that's need tho, it works fine on my test form!

Cheers

Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top