The IIf and Year(date)

G

Guest

I am new to this and i just wanted to know, if and can you use a IIf
statement in a default value property. I use a IIf and when i go to the form
in form view, it is blank, the queries in th RowSource are set for the field
in the table. Here is the expression that i used.

=IIf(IsNull([Forms]![EDIT].[FY].[Year(Date)+1]),0,[Forms]![EDIT].[FY].[Year(Date)])

This is making my form blank (i think) in form view.

Help please anyone!
 
D

Douglas J. Steele

In words, what are you trying to do?

Forms]![EDIT].[FY].[Year(Date)+1] and [Forms]![EDIT].[FY].[Year(Date)]
definitely aren't valid, but I'm not sure what you should have instead,
since I'm not sure what it is you're trying to do.
 
B

BruceM

What are [EDIT], [FY], and [Year(Date)]? What exactly are you trying to do?
I don't see a reason you couldn't use IIf as a default value expression
(although I have to admit I haven't tried), but the expression is not going
to do anything.
The default value is applied only when you first go to a new record, if that
helps.
 
G

Guest

I am so sorry, I explained that wrong. i needed to know if it was possible to
calculate a combo box that has year dates in it and if a new year comes
around, the new year date would be defaulted in the combo box when the form
opens. Is it possible to do this in the defaultvalue property on the combo
box without having to VB? The field has two-digit year "yy" and a query
builder on it. Would the iif statement be the way to go and how would i do
that?
--
Happy Days with programming!!


BruceM said:
What are [EDIT], [FY], and [Year(Date)]? What exactly are you trying to do?
I don't see a reason you couldn't use IIf as a default value expression
(although I have to admit I haven't tried), but the expression is not going
to do anything.
The default value is applied only when you first go to a new record, if that
helps.

angela said:
I am new to this and i just wanted to know, if and can you use a IIf
statement in a default value property. I use a IIf and when i go to the
form
in form view, it is blank, the queries in th RowSource are set for the
field
in the table. Here is the expression that i used.

=IIf(IsNull([Forms]![EDIT].[FY].[Year(Date)+1]),0,[Forms]![EDIT].[FY].[Year(Date)])

This is making my form blank (i think) in form view.

Help please anyone!
 
B

BruceM

Maybe I don't understand, but if the new year comes around the Year function
will produce a different number than it did the year before. However, if
you are already storing the date somewhere there is no need to store the
year. You can just extract it from the date field for display purposes on a
form or report.
If you set the default value of a date field to Date(), will that give you a
date with the correct year? Create a new record to test it out.

angela said:
I am so sorry, I explained that wrong. i needed to know if it was possible
to
calculate a combo box that has year dates in it and if a new year comes
around, the new year date would be defaulted in the combo box when the
form
opens. Is it possible to do this in the defaultvalue property on the combo
box without having to VB? The field has two-digit year "yy" and a query
builder on it. Would the iif statement be the way to go and how would i do
that?
--
Happy Days with programming!!


BruceM said:
What are [EDIT], [FY], and [Year(Date)]? What exactly are you trying to
do?
I don't see a reason you couldn't use IIf as a default value expression
(although I have to admit I haven't tried), but the expression is not
going
to do anything.
The default value is applied only when you first go to a new record, if
that
helps.

angela said:
I am new to this and i just wanted to know, if and can you use a IIf
statement in a default value property. I use a IIf and when i go to the
form
in form view, it is blank, the queries in th RowSource are set for the
field
in the table. Here is the expression that i used.

=IIf(IsNull([Forms]![EDIT].[FY].[Year(Date)+1]),0,[Forms]![EDIT].[FY].[Year(Date)])

This is making my form blank (i think) in form view.

Help please anyone!
 
G

Guest

I don't understand how to use the IIF function. i was told that i should use
it in the default value property on a form in the combo box that is storing
the field of two digit year numbers. The field has datatype number. On the
form, it is queried in the rowsource. This concerns fiscal year 10/01/year -
09/30/year. If a record is inputted by the user in this year or next year,
the combo box drop down that has the stored values from the field in the
table, should automatically go to this year "07" or (next year "08"). All
years (00 - 07) should be visible in the drop down box at all times and if a
user adds or deletes a record the drop down should reflect this. The
statement earlier is what i tried to write but saw that the references were
wrong.

IIf(cbo = table!field, year(field)+1, year(field))

When i write it like this i am getting a blank form when it loads.

thanks for any help anyone.


--
Happy Days with programming!!


BruceM said:
Maybe I don't understand, but if the new year comes around the Year function
will produce a different number than it did the year before. However, if
you are already storing the date somewhere there is no need to store the
year. You can just extract it from the date field for display purposes on a
form or report.
If you set the default value of a date field to Date(), will that give you a
date with the correct year? Create a new record to test it out.

angela said:
I am so sorry, I explained that wrong. i needed to know if it was possible
to
calculate a combo box that has year dates in it and if a new year comes
around, the new year date would be defaulted in the combo box when the
form
opens. Is it possible to do this in the defaultvalue property on the combo
box without having to VB? The field has two-digit year "yy" and a query
builder on it. Would the iif statement be the way to go and how would i do
that?
--
Happy Days with programming!!


BruceM said:
What are [EDIT], [FY], and [Year(Date)]? What exactly are you trying to
do?
I don't see a reason you couldn't use IIf as a default value expression
(although I have to admit I haven't tried), but the expression is not
going
to do anything.
The default value is applied only when you first go to a new record, if
that
helps.

I am new to this and i just wanted to know, if and can you use a IIf
statement in a default value property. I use a IIf and when i go to the
form
in form view, it is blank, the queries in th RowSource are set for the
field
in the table. Here is the expression that i used.

=IIf(IsNull([Forms]![EDIT].[FY].[Year(Date)+1]),0,[Forms]![EDIT].[FY].[Year(Date)])

This is making my form blank (i think) in form view.

Help please anyone!
 
B

BruceM

Here's how the IIf function works (using expressive rather than literal
language):
If a condition is met, do something, otherwise do something else. In the
context of the IIf function:
IIF(Condition is met,do something,do something else)
For instance, if today is later than a date field (I will call it
ExpirationDate), show text to that effect, otherwise show different text.
In an unbound text box, the Control Source would be:
IIf(Date()>[ExpirationDate],"Expired","OK")
Now, to the question at hand. What do you mean by "the default value
property on a form in the combo box that is storing the field of two digit
year numbers"? A combo box can be on a form, but I can't be sure what you
mean by "a form in the combo box". I explained the default value property
in an earlier posting. Was that clear. An example of using the default
property is to set it to Date() for a date field, so that today's date is
automatically filled in when a new record is created. After the record has
been saved (by navigating away from it, for instance), the default property
no longer applies.
Describe what you want to happen if a record is input today. What do you
expect to see in the combo box? What should occur after you make the
selection?
In your expression:
IIf(cbo = table!field, year(field)+1, year(field))
try using expressive language to described what should happen. I don't
think the default property will do what you need, but unfortunately I can't
figure out just what you need, so I am at a loss to suggest anything
specific.

angela said:
I don't understand how to use the IIF function. i was told that i should
use
it in the default value property on a form in the combo box that is
storing
the field of two digit year numbers. The field has datatype number. On the
form, it is queried in the rowsource. This concerns fiscal year
10/01/year -
09/30/year. If a record is inputted by the user in this year or next year,
the combo box drop down that has the stored values from the field in the
table, should automatically go to this year "07" or (next year "08"). All
years (00 - 07) should be visible in the drop down box at all times and if
a
user adds or deletes a record the drop down should reflect this. The
statement earlier is what i tried to write but saw that the references
were
wrong.

IIf(cbo = table!field, year(field)+1, year(field))

When i write it like this i am getting a blank form when it loads.

thanks for any help anyone.


--
Happy Days with programming!!


BruceM said:
Maybe I don't understand, but if the new year comes around the Year
function
will produce a different number than it did the year before. However, if
you are already storing the date somewhere there is no need to store the
year. You can just extract it from the date field for display purposes
on a
form or report.
If you set the default value of a date field to Date(), will that give
you a
date with the correct year? Create a new record to test it out.

angela said:
I am so sorry, I explained that wrong. i needed to know if it was
possible
to
calculate a combo box that has year dates in it and if a new year comes
around, the new year date would be defaulted in the combo box when the
form
opens. Is it possible to do this in the defaultvalue property on the
combo
box without having to VB? The field has two-digit year "yy" and a query
builder on it. Would the iif statement be the way to go and how would i
do
that?
--
Happy Days with programming!!


:

What are [EDIT], [FY], and [Year(Date)]? What exactly are you trying
to
do?
I don't see a reason you couldn't use IIf as a default value
expression
(although I have to admit I haven't tried), but the expression is not
going
to do anything.
The default value is applied only when you first go to a new record,
if
that
helps.

I am new to this and i just wanted to know, if and can you use a IIf
statement in a default value property. I use a IIf and when i go to
the
form
in form view, it is blank, the queries in th RowSource are set for
the
field
in the table. Here is the expression that i used.

=IIf(IsNull([Forms]![EDIT].[FY].[Year(Date)+1]),0,[Forms]![EDIT].[FY].[Year(Date)])

This is making my form blank (i think) in form view.

Help please anyone!
 

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