Change data on Date

B

Bob Vance

On My form I am Trying to write a code if the Horse is 3 years old F changes
to M (Text)
If [cbSex] > Year 3 [cbDateof Birth] repalce F with M
 
K

Ken Snell \(MVP\)

Generic expression:

=IIf([AgeOfHorse] > 3, Replace([SexOfHorse], "F", "M"), [SexOfHorse])
 
G

George

You need to know if the horse is a filly or a mare, and the criterion is
that the filly becomes a mare on the date when she turns 3 years old?

If that's the correct rule, you can display her status (which you don't need
to store, by the way, because it is a calculation)

IIf(DateDiff("yyyy",[tblHorse].[DateofBirth],Now())+Int(Format(Now(),"mmdd")<Format([tblHorse].[DateofBirth],"mmdd"))<3,"F","M")

I mention the fact that you don't store this because your prefix "cb - Sex"
implies a combo box, which is not necessary if you are only DISPLAYING the
calculated status. A text box will work just fine.
 
G

George

If I misinterpreted the rule, and the change occurs on the horse's 4th
birthday, then just change 3 to 4 in the formula.


George said:
You need to know if the horse is a filly or a mare, and the criterion is
that the filly becomes a mare on the date when she turns 3 years old?

If that's the correct rule, you can display her status (which you don't
need to store, by the way, because it is a calculation)

IIf(DateDiff("yyyy",[tblHorse].[DateofBirth],Now())+Int(Format(Now(),"mmdd")<Format([tblHorse].[DateofBirth],"mmdd"))<3,"F","M")

I mention the fact that you don't store this because your prefix "cb -
Sex" implies a combo box, which is not necessary if you are only
DISPLAYING the calculated status. A text box will work just fine.



Bob Vance said:
On My form I am Trying to write a code if the Horse is 3 years old F
changes to M (Text)
If [cbSex] > Year 3 [cbDateof Birth] repalce F with M
 
B

Bob Vance

Thanks Ken where do i place this code..............Thanks Bob
=IIf([tbAge] > 3, Replace([cbsex], "F", "M"), [cbsex])

Ken Snell (MVP) said:
Generic expression:

=IIf([AgeOfHorse] > 3, Replace([SexOfHorse], "F", "M"), [SexOfHorse])

--

Ken Snell
<MS ACCESS MVP>




Bob Vance said:
On My form I am Trying to write a code if the Horse is 3 years old F
changes to M (Text)
If [cbSex] > Year 3 [cbDateof Birth] repalce F with M
 
B

Bob Vance

George I use the combo box to select either M,F,C,G when I enter the horse
into my db but when the F turns 4yo she becomes a M
Thanks Bob
George said:
You need to know if the horse is a filly or a mare, and the criterion is
that the filly becomes a mare on the date when she turns 3 years old?

If that's the correct rule, you can display her status (which you don't
need to store, by the way, because it is a calculation)

IIf(DateDiff("yyyy",[tblHorse].[DateofBirth],Now())+Int(Format(Now(),"mmdd")<Format([tblHorse].[DateofBirth],"mmdd"))<3,"F","M")

I mention the fact that you don't store this because your prefix "cb -
Sex" implies a combo box, which is not necessary if you are only
DISPLAYING the calculated status. A text box will work just fine.



Bob Vance said:
On My form I am Trying to write a code if the Horse is 3 years old F
changes to M (Text)
If [cbSex] > Year 3 [cbDateof Birth] repalce F with M
 
B

Bob Vance

Thanks Ken Got it put it in a Query!
Regards Bob

Bob Vance said:
Thanks Ken where do i place this code..............Thanks Bob
=IIf([tbAge] > 3, Replace([cbsex], "F", "M"), [cbsex])

Ken Snell (MVP) said:
Generic expression:

=IIf([AgeOfHorse] > 3, Replace([SexOfHorse], "F", "M"), [SexOfHorse])

--

Ken Snell
<MS ACCESS MVP>




Bob Vance said:
On My form I am Trying to write a code if the Horse is 3 years old F
changes to M (Text)
If [cbSex] > Year 3 [cbDateof Birth] repalce F with M
 
K

Ken Snell \(MVP\)

Bob Vance said:
Thanks Ken Got it put it in a Query!

Or use it as the expression for a textbox's ControlSource property.
--

Ken Snell
<MS ACCESS MVP>





Regards Bob

Bob Vance said:
Thanks Ken where do i place this code..............Thanks Bob
=IIf([tbAge] > 3, Replace([cbsex], "F", "M"), [cbsex])

Ken Snell (MVP) said:
Generic expression:

=IIf([AgeOfHorse] > 3, Replace([SexOfHorse], "F", "M"), [SexOfHorse])

--

Ken Snell
<MS ACCESS MVP>




On My form I am Trying to write a code if the Horse is 3 years old F
changes to M (Text)
If [cbSex] > Year 3 [cbDateof Birth] repalce F with M
 
B

Bob Vance

Thanks Ken, would not work in a textbox Control source...thanks Bob

Ken Snell (MVP) said:
Bob Vance said:
Thanks Ken Got it put it in a Query!

Or use it as the expression for a textbox's ControlSource property.
--

Ken Snell
<MS ACCESS MVP>





Regards Bob

Bob Vance said:
Thanks Ken where do i place this code..............Thanks Bob
=IIf([tbAge] > 3, Replace([cbsex], "F", "M"), [cbsex])

Generic expression:

=IIf([AgeOfHorse] > 3, Replace([SexOfHorse], "F", "M"), [SexOfHorse])

--

Ken Snell
<MS ACCESS MVP>




On My form I am Trying to write a code if the Horse is 3 years old F
changes to M (Text)
If [cbSex] > Year 3 [cbDateof Birth] repalce F with M
 
Top