tags:

views:

32

answers:

1

I am trying to link a checkbox to a date. So when the user Clicks the checkbox it automaticly puts in the current date.

+2  A: 

In the AfterUpdate event of the CheckBox control you'd add this code, where chkCurrentDate is the name of the checkbox and txtDate is the name of the textbox bound to the date field:

  If (Me!chkCurrentDate) Then 
     Me!txtDate = Date()
  End If

Now, you haven't specified what you want to happen if the check is already checked -- change the date? Remove the date?

This leads me to the next point:

I'm not sure you've chosen the right controls to do this.

If you use an unbound checkbox to populate a date field, you're using it like a command button. I would suggest that a command button makes more sense.

But that might not even be necessary -- it depends on what is triggering the need to enter the current date. If you want a new record to be stamped with the current data, you could use the .DefaultValue property of your control that displays the data to the Date() function (or, in the field definition in the table, set the DefaultValue to Date()).

But it might be that you want to stamp the record with the current data because it's being updated. In that case, you'd use the Form's BeforeUpdate event to set the date value.

And it might be that your checkbox is, in fact, bound to a field in the form's recordsource, in which case, you really would need to determine what to do if the check is cleared.

Perhaps you could describe what your form is editing and what process is triggering the need to enter the current date and then determine better which of the many possible approaches makes the most sense.

David-W-Fenton
I run a tutoring program at a middle school and part of my job is to track missing homework assignments. The database allows the teachers to input the missing assignment along with other fields such as Name, Referral Data, Hour, Grade, Subject.Once the Student has completed the assignment the teacher opens the Completion Form types in the Completed date and checks the Completed Check boxes. I use the Completed Check box for stats I keep on each student and teacher.What I want to do is to just have the teacher check the Completed Check box and have the date fill the Completed date box.
Mike
Do you have multiple assignments stored in one table? If so, that's a design error, as if you had them in a separate table, one assignment per record, you'd just have a command button that inserts the record in the table, and it would default to the current date. For what you're doing, however, is it not the case that my first suggestion works?
David-W-Fenton