From: Diego via AccessMonster.com on
Hi All
i have a date field called Data_Nascita and and unbound field to calculate
the age (called Anni) with
=DateDiff("yyyy",[Data_Nascita],Date())-IIf(Format([Data_Nascita],"mmdd")
>Format(Date(),"mmdd"),1,0)
this works enoght.

Now i want to write automatically other two fields (Categoria and Descrizione)
in the form related to age (Anni) value.
I start to write this code (after update of unbounded field) but it does not
work

If Me.Anni = 12 Then
Me.Categoria = "P_1" And Me.Descrizione = "Pulcini 1_A"
ElseIf Me.Anni = 13 Then
Me.Categoria = "P_2" And Me.Descrizione = "Pulcini 2_A"
ElseIf Me.Anni = 14 Then
Me.Categoria = "P_3" And Me.Descrizione = "Pulcini 3_A"
End If

I have not any error, but the Categoria adn Descrizione field are not updated
(empty)
Can you help me ?

Best regards
Diego

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201005/1

From: Al Campagna on
Diego,
Since those values depend on the Data_Nascita, you need to use the
AfterUpdate event of Data_Nascita to update those fields.
Also, you can't use the "and" to update the Descrizione.
> If Me.Anni = 12 Then
> Me.Categoria = "P_1"
Me.Descrizione = "Pulcini 1_A"
> ElseIf Me.Anni = 13 Then
> Me.Categoria = "P_2"
Me.Descrizione = "Pulcini 2_A"
> ElseIf Me.Anni = 14 Then
> Me.Categoria = "P_3"
Me.Descrizione = "Pulcini 3_A"
> End If

But... you'll probably also need to have that same code on the Form's
OnCurrent event, so... as a person's age increases, the Categoria and
Descrizione
will adjust when the user views/browses that record.
--
hth
Al Campagna
Microsoft Access MVP 2007-2009
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."

"Diego via AccessMonster.com" <u28514(a)uwe> wrote in message
news:a77234e1ef7ee(a)uwe...
> Hi All
> i have a date field called Data_Nascita and and unbound field to calculate
> the age (called Anni) with
> =DateDiff("yyyy",[Data_Nascita],Date())-IIf(Format([Data_Nascita],"mmdd")
>>Format(Date(),"mmdd"),1,0)
> this works enoght.
>
> Now i want to write automatically other two fields (Categoria and
> Descrizione)
> in the form related to age (Anni) value.
> I start to write this code (after update of unbounded field) but it does
> not
> work
>
> If Me.Anni = 12 Then
> Me.Categoria = "P_1" And Me.Descrizione = "Pulcini 1_A"
> ElseIf Me.Anni = 13 Then
> Me.Categoria = "P_2" And Me.Descrizione = "Pulcini 2_A"
> ElseIf Me.Anni = 14 Then
> Me.Categoria = "P_3" And Me.Descrizione = "Pulcini 3_A"
> End If
>
> I have not any error, but the Categoria adn Descrizione field are not
> updated
> (empty)
> Can you help me ?
>
> Best regards
> Diego
>
> --
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201005/1
>


From: Diego via AccessMonster.com on
It does not works
the problem seems to be in the age calculation

Anni is a unbounded field, that gives a good age value, but when i use in the
expression it does not works.
Diego

Al Campagna wrote:
>Diego,
> Since those values depend on the Data_Nascita, you need to use the
>AfterUpdate event of Data_Nascita to update those fields.
> Also, you can't use the "and" to update the Descrizione.
>> If Me.Anni = 12 Then
>> Me.Categoria = "P_1"
> Me.Descrizione = "Pulcini 1_A"
>> ElseIf Me.Anni = 13 Then
>> Me.Categoria = "P_2"
> Me.Descrizione = "Pulcini 2_A"
>> ElseIf Me.Anni = 14 Then
>> Me.Categoria = "P_3"
> Me.Descrizione = "Pulcini 3_A"
>> End If
>
> But... you'll probably also need to have that same code on the Form's
>OnCurrent event, so... as a person's age increases, the Categoria and
>Descrizione
>will adjust when the user views/browses that record.
>> Hi All
>> i have a date field called Data_Nascita and and unbound field to calculate
>[quoted text clipped - 25 lines]
>> Best regards
>> Diego

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201005/1

From: Al Campagna on
Diego,
You <clipped> your Anni formula from the thread. Please only clip
non-essential text from previous posts.
*=DateDiff("yyyy",[Data_Nascita],Date())-IIf(Format([Data_Nascita],"mmdd")
*>Format(Date(),"mmdd"),1,0)

Whenever you use suggested code, and have a problem, Cut & Paste that
code
into your reply. That way we can say, yes or no, that your code is OK.
I agree that the problem is probably the Anni calculation.

Try this Anni...
=DateDiff("yyyy",[Anni],Now())+(Int(Format(Now(),"mmdd")<Int(Format([Anni],"mmdd"))))

I tested this, and it works with my code...
--
hth
Al Campagna
Microsoft Access MVP 2007-2009
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."


"Diego via AccessMonster.com" <u28514(a)uwe> wrote in message
news:a7748a1d29537(a)uwe...
> It does not works
> the problem seems to be in the age calculation
>
> Anni is a unbounded field, that gives a good age value, but when i use in
> the
> expression it does not works.
> Diego
>
> Al Campagna wrote:
>>Diego,
>> Since those values depend on the Data_Nascita, you need to use the
>>AfterUpdate event of Data_Nascita to update those fields.
>> Also, you can't use the "and" to update the Descrizione.
>>> If Me.Anni = 12 Then
>>> Me.Categoria = "P_1"
>> Me.Descrizione = "Pulcini 1_A"
>>> ElseIf Me.Anni = 13 Then
>>> Me.Categoria = "P_2"
>> Me.Descrizione = "Pulcini 2_A"
>>> ElseIf Me.Anni = 14 Then
>>> Me.Categoria = "P_3"
>> Me.Descrizione = "Pulcini 3_A"
>>> End If
>>
>> But... you'll probably also need to have that same code on the Form's
>>OnCurrent event, so... as a person's age increases, the Categoria and
>>Descrizione
>>will adjust when the user views/browses that record.
>>> Hi All
>>> i have a date field called Data_Nascita and and unbound field to
>>> calculate
>>[quoted text clipped - 25 lines]
>>> Best regards
>>> Diego
>
> --
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201005/1
>


From: Linq Adams via AccessMonster.com on
Actually, you can use the expression as the Control Source of the unbound
textbox and it works fine, and will update automatically as the person ages.

Al's suggestion of using the Data_Nascita_AfterUpdate event as well as the
Form_Current event would, of course, also work. It's simply a matter of style.


Where exactly are you trying to use the expression?

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via http://www.accessmonster.com

 |  Next  |  Last
Pages: 1 2 3 4 5
Prev: cancel form unload
Next: MDE in A2003, A2007