开发者

Linking a Checkbox to date

I am trying to开发者_JAVA技巧 link a checkbox to a date. So when the user Clicks the checkbox it automaticly puts in the current date.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜