By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 2,171 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 IT Pros & Developers. It's quick & easy.

Automatic Date Entry

P: n/a
Hi,

I have a check box on one of my forms, let call the field "ceased?",
and when it is checked I would like the current date put into my date
field and the "ceased?" field protected.
Would anyone know the code to do this?
Any help would be greatly appreciated
Cheers

Zie

Jan 6 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Use the AfterUpdate event procedure of the check box to drop the date into
your other field:
Private Sub ceased_AfterUpdate()
If Me.ceased.Value Then
Me.CeasedDate = Date
Else
Me.CeasedDate = Null
End If
End Sub

In the Current event of the form:
Private Sub Form_Current()
Dim bDisabled As Boolean
With Me.ceased
bDisabled = Nz(.Value, False)
If .Enabled = bDisabled Then
.Enabled = Not bDisabled
End If
End With
End Sub

You need to add error handling to Form_Current, to handle the case where the
ceased check box cannot be disabled because it has focus.

The code above will make the ceased check box disabled next time you load
the record in the form once it has been checked.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<z.******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

I have a check box on one of my forms, let call the field "ceased?",
and when it is checked I would like the current date put into my date
field and the "ceased?" field protected.
Would anyone know the code to do this?
Any help would be greatly appreciated

Jan 6 '06 #2

P: n/a
Your can use this code on the AfterUpdate of the chekbox and use some
code on the current as Allen said.

RetValue = MsgBox("Do you really want to cease?", vbYesNoCancel +
vbExclamation, "Cease")
Select Case RetValue
Case Is = vbNo
Me.Ceased = False
Case Is = vbCancel
Me.Ceased = False
Case Is = vbYes
Me.txtDate = Now()
Me.SomeControl.SetFocus
Me.Ceased.Enabled = False
End Select

GAVO.

Jan 6 '06 #3

P: n/a
z.******@gmail.com wrote:
Hi,

I have a check box on one of my forms, let call the field "ceased?",
and when it is checked I would like the current date put into my date
field and the "ceased?" field protected.
Would anyone know the code to do this?
Any help would be greatly appreciated
Cheers

Zie


The other responses have answered your question, but I thought I would point
out that (it appears) that you have a redundant and unnecessary field in
your table. If all "ceased" records will have a CeaseDate and all records
that are not "ceased" will have a Null in CeaseDate, then you really don't
need the Yes/No field for [ceased] at all. It is telling you the same
information that you can derive by looking at the CeaseDate field.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Jan 6 '06 #4

P: n/a
Red

Rick Brandt wrote:
The other responses have answered your question, but I thought I would point
out that (it appears) that you have a redundant and unnecessary field in
your table. If all "ceased" records will have a CeaseDate and all records
that are not "ceased" will have a Null in CeaseDate, then you really don't
need the Yes/No field for [ceased] at all. It is telling you the same
information that you can derive by looking at the CeaseDate field.


I completely understand that, but try explaining that to non-computer
literate co-workers =P

Jan 7 '06 #5

P: n/a
"Red" <do**********@gmail.com> wrote in
news:11*********************@g14g2000cwa.googlegro ups.com:

Rick Brandt wrote:
The other responses have answered your question, but I
thought I would point out that (it appears) that you have a
redundant and unnecessary field in your table. If all
"ceased" records will have a CeaseDate and all records that
are not "ceased" will have a Null in CeaseDate, then you
really don't need the Yes/No field for [ceased] at all. It
is telling you the same information that you can derive by
looking at the CeaseDate field.


I completely understand that, but try explaining that to
non-computer literate co-workers =P

Since a good rule of database application development is to
never expose the underlying tables or queries to the user, but
to always use forms and reports, the non-computer literates
would never know.
I have many forms where a label displaying "this item is
closed" is on the form but is set in code based on the nullity
of a date field, and not stored in the table..
--
Bob Quintal

PA is y I've altered my email address.
Jan 7 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.