Set unbound textbox default value = current year (1 Viewer)

xBirdman

Registered User.
Local time
Today, 07:29
Joined
Oct 14, 2019
Messages
38
Hi guys,
I'm trying to do what I thought would be very simple, but...

I added an unbound textbox to a form. The user will enter the 4 digit year into the box to filter an underlying query. 95% of the time, the year will be the current year, so I'd like to set that as default for the field. Based on several posts I've tried =YEAR(date()) and =DatePart('yyyy',Date()) as well as wrapping as a character string =CStr(Year(date())).

However, when I open the form I just get a '#Name?' error in the field. When I researched that the common theme seems to be naming the field something that creates a circular reference on the form, but the name of the field is txtCurrentDate and there's nothing else on the form with 'year' or 'date' in the name.

What the heck am I doing wrong here? I'm sure it is simple. Please ridicule me... I feel deserving. :banghead:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:29
Joined
Oct 29, 2018
Messages
21,449
Hi. Since we can't see your form, could you please confirm for us exactly where you're entering these expressions? Thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 22:29
Joined
May 7, 2009
Messages
19,231
use Default Value(Property Sheet->Data) property of the unbound textbox:

=Year(Date())

and remove the expression (=Expr) from the textbox control source.
 

xBirdman

Registered User.
Local time
Today, 07:29
Joined
Oct 14, 2019
Messages
38
SorryDBGuy, meant to include that I entered those expressions into the default value property of the textbox.

As noted, this is a brand new text box that I've changed nothing about except the name. On a lark, I just created a second new textbox, and used the =Year(Date()) suggested by arnelgp and it works. ???

Two boxes, same code, one generates the error, the other doesn't.

Thanks for the quick responses guys. This will leave me scratching my head.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:29
Joined
Oct 29, 2018
Messages
21,449
SorryDBGuy, meant to include that I entered those expressions into the default value property of the textbox.

As noted, this is a brand new text box that I've changed nothing about except the name. On a lark, I just created a second new textbox, and used the =Year(Date()) suggested by arnelgp and it works. ???

Two boxes, same code, one generates the error, the other doesn't.

Thanks for the quick responses guys. This will leave me scratching my head.
Hi. Glad to hear you got it sorted out. If you want us to take a look and maybe figure out why there's a difference in behavior between the two textboxes, maybe you could post a sample copy of the db with the problematic form. Just a thought...
 

xBirdman

Registered User.
Local time
Today, 07:29
Joined
Oct 14, 2019
Messages
38
Thanks. I wish I could as it would make some of my tasks so much easier, but I'm working behind serious security walls because it is very sensitive personal data. Worse, it is a very old database that was very poorly designed. I'll have to content myself with posting questions and trying to be as descriptive as possible, or mock up examples with dummy data. The upside is I've already learned a lot of tricks just by searching the forums. Thanks for a great resource.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:29
Joined
Oct 29, 2018
Messages
21,449
Thanks. I wish I could as it would make some of my tasks so much easier, but I'm working behind serious security walls because it is very sensitive personal data. Worse, it is a very old database that was very poorly designed. I'll have to content myself with posting questions and trying to be as descriptive as possible, or mock up examples with dummy data. The upside is I've already learned a lot of tricks just by searching the forums. Thanks for a great resource.
No worries. We understand. Good luck!
 

Users who are viewing this thread

Top Bottom