Forcing the Current Date into a Form Field when a Checkbox is Clic

J

John Spencer

Do you have a control bound to the field? What is the name of the control?

I would try

Me.[Expiry Date] = Now()

Also, you do know that Now() will return the date AND the time? If you want
just the date then use

Me.[Expiry Date] = Date()


SkyGuy said:
Ok...here's my current code, which is working (somewhat). I change
Terminated
from "No" to "Yes" and Expiry Date remains blank. But after after I move
to
the next/previous record, then go back to the record that I set Terminated
to
"Yes", the Expiry Date will display the current date.

Private Sub Terminated_Change()
If Me.Terminated = "-1" Then
Me![Expiry Date].Value = Now()
MsgBox "Yes, I work!", vbOKOnly, "Test"
Else
MsgBox "No, I don't work!", vbOKOnly, "Test"
End If

End Sub

John Spencer said:
Pardon me, but I think that the Row source being Yes; No might end up
being
True/False when you are testing the value.

Using your earlier test technique

Msgbox "The value is " & me.terminated

IF the message comes back
The value is -1 or The value is 0 then you probably are returning true
and
false.

If the message is
The value is <blank> then you know that somehow your combobox is not
retaining the value.

SkyGuy said:
Yes Gina, the Terminated form field has a little arrow to select from a
list.
So it is a combo box. Sorry for the mix up in terminology...I'm new to
this.

Bob

:

Selection LIst? You mean it's NOT a combo box? Combo Box has a
little
arrow where you select from a list.


Bound Column: 1
Column Count: 1
Row Source: Yes;No
Row Source Type: Value List

I'm not sure what you mean by combo box. But on the form, Terminated
is
a
selection list w/either a value of No or Yes. So I guess the correct
answer
to your first question is 2 rows.

:

Okay but at least we now know the code is being read! Your combo
box,
is
that a single row not 2 row

1;Yes
2;No

and the bound column is 1?

Please look at the Property Window of Terminated, what you should
see
is
Column Count = 1 and Bound Column = 1 and Row Source = Yes;No and
Row
Source
Type = Value List.


Gina,

A pop-up msg appeared that said "No, I don't work!". That was
cool.
But
obviously I still have a problem.

Bob

:

Please try pasting the below code and then change the combo box.
Does
a
message come up?

If Me.Terminated = "Yes" Then
'Me.[Expiry Date] = Date
MsgBox "Yes, I work!", vbOkOnly, "Test"
Else
MsgBox "No, I don't work!", vbOkOnly, "Test"
End If


Gina,

I replied to your post but it looks like it didn't take. So
here's
another
post.
First of all...thanks for your help...but my Date field is
still
not
populating.

I'm using MS Access 2002.

In Design View, I right-clicked on the Terminated Field,
selected
Properties, then scrolled down to After Update and clicked on
the
drop-down
arrow. There was only one choice; [Event Procedure]. I
selected
this
then
clicked on the elipses button to the right. A windows opened
and
I
pasted
my
code just below the "Private Sub Terminated_AfterUpdate()" and
did a
save.

Here's a copy of my code:

Private Sub Terminated_AfterUpdate()

If Me.[Terminated] = "Yes" Then
Me.[Expiry Date] = Date
End If


End Sub

Thanks again,
Bob


:

My 2 cents worth...

You said you went to ' form's Terminated field in Design View
then
'
(you
just want to make sure it's not on the After Update of the
form
because
it
needs to be on the After Update of the control)

Okay not sure the code is in the correct place, so just check

1. Go to Design View on the form
2. Go click on you field ' Terminated ' and then right mouse
click
if
Properties Window for your field is not showing and select
Properties.
3. In the Properties Window for your field scroll down till
you
find
the
After Update Event and select ... Build Event
4. Place your code, close and save. Try it, if that does not
work
post
back.

If you have already done the above "NEVERMIND"

The () after Date sometime disappears on mine to, still does
wht
it's
suppose to.

Gina

choice Build Event"SkyGuy"
<[email protected]>
wrote
in
message
Ok Ed...I right-clicked on the form's Terminated field in
Design
View
then
choice Build Event. I then chose "After Update" from the
drop-down
list
in
Visual Basic. But when I do a save Visual Basic eliminates
the
()
after
=Date
and the solution does not work. What am I doing
wrong...thanks.

:

OK, just change it to:

If Me.[Terminated] = "Yes" Then
Me.[Expiration Date] = Date()
End if


message
I apologize Ed...Terminated is not a Checkbox. It's a
Selection
List
with
either a value of Yes or No. So if I select Yes in
Terminated
I
want
the
Experiation field to be populated with today's date.
Again,
sorry
for
the
initial misinformation.
Bob

:

In the AfterUpdate event of your checkbox, put:

If Me.[Terminated] = -1 then
Me.[Expiration Date] = Date()
End if

-Ed



message
Hello,

I'm new to Access and not familiar with Events,
Procedures
or
Visual
Basic.

I have a form with a Date Field called "Expiration
Date".
In
the
same
form
I
have a Checkbox called "Terminated".

I'd like the current date to automatically populate
the
Expiration
Date
when
Terminated is checked.

Any help would be very much appreciated.

Thanks,
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top