How do I make sure the year entry is current year

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a text box entry where the month, Day and year "OTDLdaTe" in required,
but after reviewing the data in the table I noticed that the year entry may
be incorrect. What could one do to the text box to make sure they year entry
in the OTDLdate text box is that of the current year? I do not need to have
current Date() as entry are not done daily.

Thanks.
 
Hi Nickm,


on the BeforeUpdate event of the control:

'~~~~~~~~~~~~~~~~~~~~~``
if not IsDate(me.activecontrol) then
msgbox "You must enter a date",,"Cannot continue
cancel = true
end if

if not year(me.activecontrol) <> year(date()) then
msgbox "Year is incorrect, must be current year",,"Cannot continue
cancel = true
end if
'~~~~~~~~~~~~~~~~~~~~~``


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
I have entered as you suggested but code does not work. I should tell you
that this in a sub form in a form footer.
 
When you say it "does not work", what does it do? Does it display an error?
Did you put Crystal's code in the BeforeUpdate event of the control that is
used to enter the date? This *is* a visible control isn't it? The user keys
in the date into this control correct?
I have entered as you suggested but code does not work. I should tell you
that this in a sub form in a form footer.
Hi Nickm,
[quoted text clipped - 29 lines]
 
When I keyed an incorrect year, I did not receive an error message asking for
the the correct year. It accepted the date entered. I did enter code in the
BeforeUpdate event.

ruralguy via AccessMonster.com said:
When you say it "does not work", what does it do? Does it display an error?
Did you put Crystal's code in the BeforeUpdate event of the control that is
used to enter the date? This *is* a visible control isn't it? The user keys
in the date into this control correct?
I have entered as you suggested but code does not work. I should tell you
that this in a sub form in a form footer.
Hi Nickm,
[quoted text clipped - 29 lines]
 
Try replacing the Me.ActiveControl with the actual name of your control.
Crystal gave you generic code and we should try specific code. You might
also put a diagnostic MsgBox at the beginning of the BeforeUpdate event to
make sure it is running properly.

MsgBox "The input date is [" & Me.ControlName & "]"

using your ControlName of course.
When I keyed an incorrect year, I did not receive an error message asking for
the the correct year. It accepted the date entered. I did enter code in the
BeforeUpdate event.
When you say it "does not work", what does it do? Does it display an error?
Did you put Crystal's code in the BeforeUpdate event of the control that is
[quoted text clipped - 9 lines]
 
I would reccomend using SQL Server and then you can use a custom datatype
and associate a RULE for it

and if that doesnt' work-- then you could use a trigger

Access doesn't allow for high-quality data



ruralguy via AccessMonster.com said:
Try replacing the Me.ActiveControl with the actual name of your control.
Crystal gave you generic code and we should try specific code. You might
also put a diagnostic MsgBox at the beginning of the BeforeUpdate event to
make sure it is running properly.

MsgBox "The input date is [" & Me.ControlName & "]"

using your ControlName of course.
When I keyed an incorrect year, I did not receive an error message asking for
the the correct year. It accepted the date entered. I did enter code in the
BeforeUpdate event.
When you say it "does not work", what does it do? Does it display an error?
Did you put Crystal's code in the BeforeUpdate event of the control
that is
[quoted text clipped - 9 lines]
 
I believe there is a slight price differential between Access and SQL Server.

Susie said:
I would reccomend using SQL Server and then you can use a custom datatype
and associate a RULE for it

and if that doesnt' work-- then you could use a trigger

Access doesn't allow for high-quality data
Try replacing the Me.ActiveControl with the actual name of your control.
Crystal gave you generic code and we should try specific code. You might
[quoted text clipped - 14 lines]
 
Thanks! I did need to use the control name.

ruralguy via AccessMonster.com said:
Try replacing the Me.ActiveControl with the actual name of your control.
Crystal gave you generic code and we should try specific code. You might
also put a diagnostic MsgBox at the beginning of the BeforeUpdate event to
make sure it is running properly.

MsgBox "The input date is [" & Me.ControlName & "]"

using your ControlName of course.
When I keyed an incorrect year, I did not receive an error message asking for
the the correct year. It accepted the date entered. I did enter code in the
BeforeUpdate event.
When you say it "does not work", what does it do? Does it display an error?
Did you put Crystal's code in the BeforeUpdate event of the control that is
[quoted text clipped - 9 lines]
 
Glad I could help Nick. Thanks for posting back with your success.
Thanks! I did need to use the control name.
Try replacing the Me.ActiveControl with the actual name of your control.
Crystal gave you generic code and we should try specific code. You might
[quoted text clipped - 14 lines]
 

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

Back
Top