A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Access 2003 - Setting default value of a text box



 
 
Thread Tools Display Modes
  #1  
Old October 19th, 2009, 05:34 PM posted to microsoft.public.access.forms
Amanda
external usenet poster
 
Posts: 335
Default Access 2003 - Setting default value of a text box

I have 2 text boxes in a form that default to two set dates. I'd like to
update the form so that txtStartDate is the first date of last month and
txtEndDate is the last date of this month. For example, if I were to pull
the form up today, I'd like txtStateDate's default to be 9/1/09 and
txtEndDate's default to be 10/31/09. If I pull it up the form in November,
txtStartDate should be 10/1/09 and txtEndDate is 11/31/09.

Both text boxes are unbound. Any suggestions?
  #2  
Old October 19th, 2009, 06:10 PM posted to microsoft.public.access.forms
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default Access 2003 - Setting default value of a text box

"Amanda" wrote in message
...
I have 2 text boxes in a form that default to two set dates. I'd like to
update the form so that txtStartDate is the first date of last month and
txtEndDate is the last date of this month. For example, if I were to pull
the form up today, I'd like txtStateDate's default to be 9/1/09 and
txtEndDate's default to be 10/31/09. If I pull it up the form in
November,
txtStartDate should be 10/1/09 and txtEndDate is 11/31/09.

Both text boxes are unbound. Any suggestions?


Add these 2 functions to a standard module and call them from the
DefaultValue property:

Function BeginLastMonth()
BeginLastMonth = DateAdd("m", -1, DateSerial(Year(Date), Month(Date), 1))
End Function

Function LastDOM (DateInAMonth)
LastDOM = Day(DateSerial(Year(DateInAMonth), Month(DateInAMonth) + 1, 0))
End Function
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


  #3  
Old October 19th, 2009, 06:20 PM posted to microsoft.public.access.forms
Klatuu
external usenet poster
 
Posts: 7,074
Default Access 2003 - Setting default value of a text box

?dateserial(year(date),month(date)-1,1)
9/1/2009
?dateserial(year(date), month(date)+1,0)
10/31/2009
--
Dave Hargis, Microsoft Access MVP


"Amanda" wrote:

I have 2 text boxes in a form that default to two set dates. I'd like to
update the form so that txtStartDate is the first date of last month and
txtEndDate is the last date of this month. For example, if I were to pull
the form up today, I'd like txtStateDate's default to be 9/1/09 and
txtEndDate's default to be 10/31/09. If I pull it up the form in November,
txtStartDate should be 10/1/09 and txtEndDate is 11/31/09.

Both text boxes are unbound. Any suggestions?

  #4  
Old October 20th, 2009, 09:49 PM posted to microsoft.public.access.forms
Amanda
external usenet poster
 
Posts: 335
Default Access 2003 - Setting default value of a text box

Thank you for your response! However, if I input

?dateserial(year(date),month(date)-1,1)

Access says there's an invalid operator in my expression. If I take the
question mark away, Access automatically updates the line to:

DateSerial(Year("Date"),Month("Date")-1,1)

And my text box gives me an #Error value. I've tried taking the quotes
away, but Access keeps putting 'em back.

"Klatuu" wrote:

?dateserial(year(date),month(date)-1,1)
9/1/2009
?dateserial(year(date), month(date)+1,0)
10/31/2009
--
Dave Hargis, Microsoft Access MVP


"Amanda" wrote:

I have 2 text boxes in a form that default to two set dates. I'd like to
update the form so that txtStartDate is the first date of last month and
txtEndDate is the last date of this month. For example, if I were to pull
the form up today, I'd like txtStateDate's default to be 9/1/09 and
txtEndDate's default to be 10/31/09. If I pull it up the form in November,
txtStartDate should be 10/1/09 and txtEndDate is 11/31/09.

Both text boxes are unbound. Any suggestions?

  #5  
Old October 20th, 2009, 10:22 PM posted to microsoft.public.access.forms
Amanda
external usenet poster
 
Posts: 335
Default Access 2003 - Setting default value of a text box

Thank you Arvin!

The first function did what I wanted beautifully, but as I played with the
second, I realized that you didn't need the Day() function in there. If you
just use

Function LastDOM(DateInAMonth)
LastDOM = DateSerial(Year(DateInAMonth), Month(DateInAMonth) + 1, 0)
End Function

It returns the last day of the month. Thank you both though for the help!

"Arvin Meyer [MVP]" wrote:

"Amanda" wrote in message
...
I have 2 text boxes in a form that default to two set dates. I'd like to
update the form so that txtStartDate is the first date of last month and
txtEndDate is the last date of this month. For example, if I were to pull
the form up today, I'd like txtStateDate's default to be 9/1/09 and
txtEndDate's default to be 10/31/09. If I pull it up the form in
November,
txtStartDate should be 10/1/09 and txtEndDate is 11/31/09.

Both text boxes are unbound. Any suggestions?


Add these 2 functions to a standard module and call them from the
DefaultValue property:

Function BeginLastMonth()
BeginLastMonth = DateAdd("m", -1, DateSerial(Year(Date), Month(Date), 1))
End Function

Function LastDOM (DateInAMonth)
LastDOM = Day(DateSerial(Year(DateInAMonth), Month(DateInAMonth) + 1, 0))
End Function
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


.

  #6  
Old October 23rd, 2009, 01:18 AM posted to microsoft.public.access.forms
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default Access 2003 - Setting default value of a text box

That's because Dave was doing the expression in the Immediate Window.

To use it in a query, it would look like:

Expr1: DateSerial(Year(Date()),Month(Date())-1,1)
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com



"Amanda" wrote in message
...
Thank you for your response! However, if I input

?dateserial(year(date),month(date)-1,1)

Access says there's an invalid operator in my expression. If I take the
question mark away, Access automatically updates the line to:

DateSerial(Year("Date"),Month("Date")-1,1)

And my text box gives me an #Error value. I've tried taking the quotes
away, but Access keeps putting 'em back.

"Klatuu" wrote:

?dateserial(year(date),month(date)-1,1)
9/1/2009
?dateserial(year(date), month(date)+1,0)
10/31/2009
--
Dave Hargis, Microsoft Access MVP


"Amanda" wrote:

I have 2 text boxes in a form that default to two set dates. I'd like
to
update the form so that txtStartDate is the first date of last month
and
txtEndDate is the last date of this month. For example, if I were to
pull
the form up today, I'd like txtStateDate's default to be 9/1/09 and
txtEndDate's default to be 10/31/09. If I pull it up the form in
November,
txtStartDate should be 10/1/09 and txtEndDate is 11/31/09.

Both text boxes are unbound. Any suggestions?



 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:54 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.