PC Review


Reply
Thread Tools Rate Thread

Default date

 
 
Mike from Moriches
Guest
Posts: n/a
 
      6th Feb 2011
?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

 
Reply With Quote
 
 
 
 
Mike from Moriches
Guest
Posts: n/a
 
      6th Feb 2011
?Thank you! Your solution works perfectly. I'm not skilled enough to to
create that expression.
Mike from Moriches

"Marshall Barton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Mike from Moriches wrote:
>
>>?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)
>
> --
> Marsh
> MVP [MS Access]


 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      6th Feb 2011
On Sun, 6 Feb 2011 09:49:27 -0500, "Mike from Moriches"
<(E-Mail Removed)> wrote:

>?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/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prompted to Default Date or User Option to Change Date Emine Microsoft Access Form Coding 6 5th Dec 2008 01:22 AM
Use current date in the default date form field option amcferron@mac.com Microsoft Word Document Management 4 8th Apr 2007 08:27 AM
Show Rec's AFTER certain Time AND Date WITH Default Date Entry.... kev100 via AccessMonster.com Microsoft Access Queries 1 10th Jul 2006 10:07 PM
i have two date fileds Opend date Due date, can i set default on due date so, its always = to open date on my data entry form1 Urgent Mike Saifie Microsoft Access Form Coding 1 9th Mar 2006 01:08 AM
Default display of sample date in linked workbook with blank date in source cell Barbara Martens Microsoft Excel Worksheet Functions 2 15th Apr 2004 10:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:57 AM.