SetValue in DateField if Date is Null

E

erinjpd

I currently have a macro set up so that when I edit a text field, a date
field is populated with Now(). I now want to modify this so that the date
field auto-populates ONLY if the date field is NULL. I can't figure out how
to write the expression in Expression_Builder and haven't seen anything in
the Code Builder that might work. I think it should look like this...

IIf(IsNull([PatronSignIn]![CounselStart]),Now(),[PatronSignIn]![CounselStart])

Help! (and thanks!)
 
K

Ken Snell [MVP]

You're using a macro, and you need an expression? The expression you're
suggesting is incomplete....what type of object is PatronSignIn?

I personally would use a Condition on a SetValue action and thus not change
the value unless it's empty.

Also, on which event are you trying to use this macro?
 
E

erinjpd

Thanks SO much for giving me your input! Let me explain further:

PatronSignIn the table.
CounselBy is a text field.
CounselStart is a date/time field.

Currently I DO have a SetValue MACRO set up on the "AfterUpdate" event of
CounselBy. In the Item I reference CounselStart and in the Expression, I
state "Now()".

So... a user enters info into CounselBy and after they tab out, the
CounselStart date/time field is populated with the current time.

Does this make sense? Can you direct me further to how I can get what I'm
doign to work ONLY if the CounselStart field is null -OR- another way?

Thanks!

Ken Snell said:
You're using a macro, and you need an expression? The expression you're
suggesting is incomplete....what type of object is PatronSignIn?

I personally would use a Condition on a SetValue action and thus not change
the value unless it's empty.

Also, on which event are you trying to use this macro?

--

Ken Snell
<MS ACCESS MVP>

erinjpd said:
I currently have a macro set up so that when I edit a text field, a date
field is populated with Now(). I now want to modify this so that the date
field auto-populates ONLY if the date field is NULL. I can't figure out
how
to write the expression in Expression_Builder and haven't seen anything in
the Code Builder that might work. I think it should look like this...

IIf(IsNull([PatronSignIn]![CounselStart]),Now(),[PatronSignIn]![CounselStart])

Help! (and thanks!)
 
K

Ken Snell [MVP]

You are correctly using the AfterUpdate event.

I would change your macro action to this:

Condition: Len([CounselStart] & "")=0
Action: SetValue
Control Name: CounselStart
Expression: Now()


--

Ken Snell
<MS ACCESS MVP>


erinjpd said:
Thanks SO much for giving me your input! Let me explain further:

PatronSignIn the table.
CounselBy is a text field.
CounselStart is a date/time field.

Currently I DO have a SetValue MACRO set up on the "AfterUpdate" event of
CounselBy. In the Item I reference CounselStart and in the Expression, I
state "Now()".

So... a user enters info into CounselBy and after they tab out, the
CounselStart date/time field is populated with the current time.

Does this make sense? Can you direct me further to how I can get what I'm
doign to work ONLY if the CounselStart field is null -OR- another way?

Thanks!

Ken Snell said:
You're using a macro, and you need an expression? The expression you're
suggesting is incomplete....what type of object is PatronSignIn?

I personally would use a Condition on a SetValue action and thus not
change
the value unless it's empty.

Also, on which event are you trying to use this macro?

--

Ken Snell
<MS ACCESS MVP>

erinjpd said:
I currently have a macro set up so that when I edit a text field, a date
field is populated with Now(). I now want to modify this so that the
date
field auto-populates ONLY if the date field is NULL. I can't figure
out
how
to write the expression in Expression_Builder and haven't seen anything
in
the Code Builder that might work. I think it should look like this...

IIf(IsNull([PatronSignIn]![CounselStart]),Now(),[PatronSignIn]![CounselStart])

Help! (and thanks!)
 
E

erinjpd

Thank you so SO much! Took me a minute to figure out where the "Condition"
column was in the Macro view, but I found it!

Ken Snell said:
You are correctly using the AfterUpdate event.

I would change your macro action to this:

Condition: Len([CounselStart] & "")=0
Action: SetValue
Control Name: CounselStart
Expression: Now()


--

Ken Snell
<MS ACCESS MVP>


erinjpd said:
Thanks SO much for giving me your input! Let me explain further:

PatronSignIn the table.
CounselBy is a text field.
CounselStart is a date/time field.

Currently I DO have a SetValue MACRO set up on the "AfterUpdate" event of
CounselBy. In the Item I reference CounselStart and in the Expression, I
state "Now()".

So... a user enters info into CounselBy and after they tab out, the
CounselStart date/time field is populated with the current time.

Does this make sense? Can you direct me further to how I can get what I'm
doign to work ONLY if the CounselStart field is null -OR- another way?

Thanks!

Ken Snell said:
You're using a macro, and you need an expression? The expression you're
suggesting is incomplete....what type of object is PatronSignIn?

I personally would use a Condition on a SetValue action and thus not
change
the value unless it's empty.

Also, on which event are you trying to use this macro?

--

Ken Snell
<MS ACCESS MVP>

I currently have a macro set up so that when I edit a text field, a date
field is populated with Now(). I now want to modify this so that the
date
field auto-populates ONLY if the date field is NULL. I can't figure
out
how
to write the expression in Expression_Builder and haven't seen anything
in
the Code Builder that might work. I think it should look like this...

IIf(IsNull([PatronSignIn]![CounselStart]),Now(),[PatronSignIn]![CounselStart])

Help! (and thanks!)
 
Top