Ok. I'm sure this is simple but................

  • Thread starter Thread starter James
  • Start date Start date
J

James

I have a table with a field called "Completed_Date"

I have a form with a check box which relates to another field in the table
called "Completed"

What I want to happen is.... when the user clicks the check box to indicate
that "Completed" = true the current Date & Time will be written to the field
"Completed_Date"

My head is bleeding from banging it against the desk trying to make sense
out of the Access help files.

Can anyone help me here?

T.I.A.
 
You can use either the AfterUpdate or Click event of the Check Box:

Sub chkCompleted_AfterUpdate()

If Me.chkCompleted = True Then
Me.txtCompleted_Date = Now()
End If

End Sub

The "txt" and "chk" before the field names are the control names. This is
none to avoid and confusion between a control name and a field name.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
In the AfterUpdate event procedure of the check box control ...

If Me!NameOfCheckBoxControl = True Then
Me.Completed_Date = Now()
Else
'Assuming you want Null in the field if the user unchecks the check box
....
Me.Completed_Date = Null
End If

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
James,

The simplest way to do it: If you already have a control on your form which
is bound to the Completed_Date field in the table, fine, otherwise add one
and set its controlsource property to field Completed_Date.
I'll assume the following names, and you'll have to change accordingly:

Form name: MyForm
Checkbox control name on form: chkCompleted
Complteted Date text box on form: txtCompleted_Date

Now, while in form design, select the check box control and display
properties; go to tab Events, and put the cursor next to On Change. Notice
he little button with the three dots that appears on the right, and clock on
it; select macro builder. You will be taken to the macro design view. Go to
menu item View > Conditions to display the conditions column. Now go to the
first line condition, and type in:
Forms!MyForm!chkCompleted = True
Then move to the Actions column next to it, select action SetValue from the
list, and type in the following arguments in the bottom left hand corner of
the screen:
Item: Forms!MyForm!txtCompleted_Date
Expression: =Now()

In the second line, type in condition:
Forms!MyForm!chkCompleted = True
and action SetValue again, same Item as before, and expression: = Null()

Now save the macro giving it a meaningful name, and you're done.

HTH,
Nikos
 
Back
Top