Default date

  • Thread starter Mike from Moriches
  • Start date
M

Mike from Moriches

?I have a form to collect the date range of a report. It contains a
[startdate] control and an [enddate] control. I would like to default to a
year to date (YTD) report. My default enddate is Date(). To create a
startdate, I use the YEAR function to get the current year, then build the
string #1/1/2011#. I want this as my default startdate. I have a module
with a public function named YearStart(). The string variable I built is
named DayOne. I set the default property of startdate to YearStart(DayOne).
The control displays #Name? when I open the form. Can you tell me what I'm
doing wrong, or if there is a better way to set the default to 1/1/yyyy?
Thanks,
Mike from Moriches
 
M

Mike from Moriches

?Thank you! Your solution works perfectly. I'm not skilled enough to to
create that expression.
Mike from Moriches

Marshall Barton said:
Mike said:
?I have a form to collect the date range of a report. It contains a
[startdate] control and an [enddate] control. I would like to default to
a
year to date (YTD) report. My default enddate is Date(). To create a
startdate, I use the YEAR function to get the current year, then build the
string #1/1/2011#. I want this as my default startdate. I have a module
with a public function named YearStart(). The string variable I built is
named DayOne. I set the default property of startdate to
YearStart(DayOne).
The control displays #Name? when I open the form. Can you tell me what I'm
doing wrong, or if there is a better way to set the default to 1/1/yyyy?


I don't know what your function looks like, but I think the
problem is that VBA variables can only be used in VBA
procedures. They are totally unknown anywhere else.

On the other hand, you can use a public, standard module VBA
function almost everywhere in Access.

Based on that, I think your function could look something
like:

Public Function YearStart()
YearStart = DateSerial(Year(Date()), 1, 1)
End Function

And the DefaultValue can use that:
=YearStart()

But why create a one line function that only calls another
function. Instead, you could just set the DefaultVakue
property to:
=DateSerial(Year(Date()), 1, 1)
 
J

John W. Vinson

?I have a form to collect the date range of a report. It contains a
[startdate] control and an [enddate] control. I would like to default to a
year to date (YTD) report. My default enddate is Date(). To create a
startdate, I use the YEAR function to get the current year, then build the
string #1/1/2011#. I want this as my default startdate. I have a module
with a public function named YearStart(). The string variable I built is
named DayOne. I set the default property of startdate to YearStart(DayOne).
The control displays #Name? when I open the form. Can you tell me what I'm
doing wrong, or if there is a better way to set the default to 1/1/yyyy?
Thanks,
Mike from Moriches

The simplest way would be to set the textbox's default value to

=DateSerial(Year(Date()), 1, 1)

--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 

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