Control Code - Plus One Day

  • Thread starter Thread starter Bob V
  • Start date Start date
B

Bob V

If I had a Button what On Click code would I need to increase the date 1 day
The text box [tbStartDate1]
Thanks for any help.....Bob
 
Hi Bob,

Assumming you want to increase the date in the same text box where the date
appears:
____________

Sub cmdDatePush_click()

Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)

End Sub
____________

You'll need to add an error handler, as per standard operating procedure...

Hope that helps,
CW
 
Hi Bob,

A simple Me.tbStartDate1 = Me.tbStartDate1 +1 will do

Regards
Jacob

|
|
| If I had a Button what On Click code would I need to increase the date 1
day
| The text box [tbStartDate1]
| Thanks for any help.....Bob
|
|
 
Thanks Jk havent heard from you for a while, Its my bet this year on the Mel
Cup , we go 1/2s ;)
Bob
 
You're on

| Thanks Jk havent heard from you for a while, Its my bet this year on the
Mel
| Cup , we go 1/2s ;)
| Bob
| | > Hi Bob,
| >
| > A simple Me.tbStartDate1 = Me.tbStartDate1 +1 will do
| >
| > Regards
| > Jacob
| >
| > | > |
| > |
| > | If I had a Button what On Click code would I need to increase the date
1
| > day
| > | The text box [tbStartDate1]
| > | Thanks for any help.....Bob
| > |
| > |
| >
| >
|
|
 
Cheese, I do have a problem with this, the date format should be 12-May-07
but when I use this control to change the date I am getting 12/5/2007, I
have tried this ,but not successful.............Thanks Bob

Me.tbDayNo = DateAdd("d", 1, Me.tbDayNo)
tbDayNo.value = Format("dd-mmm-yy")

Cheese_whiz said:
Hi Bob,

Assumming you want to increase the date in the same text box where the
date
appears:
____________

Sub cmdDatePush_click()

Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)

End Sub
____________

You'll need to add an error handler, as per standard operating
procedure...

Hope that helps,
CW

Bob V said:
If I had a Button what On Click code would I need to increase the date 1
day
The text box [tbStartDate1]
Thanks for any help.....Bob
 
It does not make sense as in case of adding (or subtracting) days the two
are the same. Access keeps dates as Double type number whereby 31 Dec 1899=1
and today (15/07)=39,278. Fractions are part of a day, eg 0.5=12 hours etc

However, the important part is that you got it to work :-)

Regards
Jacob

| Oops Jacob your code did not work, Cheese Whiz did :o Thanks Cheese
|
| | > Hi Bob,
| >
| > A simple Me.tbStartDate1 = Me.tbStartDate1 +1 will do
| >
| > Regards
| > Jacob
| >
| > | > |
| > |
| > | If I had a Button what On Click code would I need to increase the date
1
| > day
| > | The text box [tbStartDate1]
| > | Thanks for any help.....Bob
| > |
| > |
| >
| >
|
|
 
Bob,

The Format() function produces a *string* - Format(Date,"dd-mmm-yy") will
produce the string "15-May-07". To apply format to a date use:

Me.tbDayNo.Format="dd-mmm-yy"

Regards
Jacob


| Cheese, I do have a problem with this, the date format should be 12-May-07
| but when I use this control to change the date I am getting 12/5/2007, I
| have tried this ,but not successful.............Thanks Bob
|
| Me.tbDayNo = DateAdd("d", 1, Me.tbDayNo)
| tbDayNo.value = Format("dd-mmm-yy")
|
| | > Hi Bob,
| >
| > Assumming you want to increase the date in the same text box where the
| > date
| > appears:
| > ____________
| >
| > Sub cmdDatePush_click()
| >
| > Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)
| >
| > End Sub
| > ____________
| >
| > You'll need to add an error handler, as per standard operating
| > procedure...
| >
| > Hope that helps,
| > CW
| >
| > "Bob V" wrote:
| >
| >>
| >>
| >> If I had a Button what On Click code would I need to increase the date
1
| >> day
| >> The text box [tbStartDate1]
| >> Thanks for any help.....Bob
| >>
| >>
| >>
|
|
 
Me.tbDayNo = DateAdd("d", -1, Me.tbDayNo)

tbDayNo.value = Format([tbDayNo], "dd-mmm-yy")

Thanks Jacob fixed it with this code
But Can I have an error catch on it
If tbDayNo = "" -1 , Now
Meaning if tbDayNo is Blank -1 from Now Date
Does that make sense! ;)
Regards Bob
 
If I understand you correctly you want yesterdays date if tbDayNo is blank.
That being the case:

1. Set the default of the field (in table design) to:
Date()-1

2. To "catch" blank dates already in the table use the Current Event:

If Not Me.NewRecord then
Me.tbDayNo=IIf(Nz(Me.tbDayNo,0)=0,Date-1,Me.tbDayNo)
End If

3. In the AfterUpdate event of the field:
Me.tbDayNo=IIf(Nz(Me.tbDayno,0)=0,Date-1,Me.tbDayNo)

Regards
Jacob


| Me.tbDayNo = DateAdd("d", -1, Me.tbDayNo)
|
| tbDayNo.value = Format([tbDayNo], "dd-mmm-yy")
|
| Thanks Jacob fixed it with this code
| But Can I have an error catch on it
| If tbDayNo = "" -1 , Now
| Meaning if tbDayNo is Blank -1 from Now Date
| Does that make sense! ;)
| Regards Bob
|
| | > Bob,
| >
| > The Format() function produces a *string* - Format(Date,"dd-mmm-yy")
will
| > produce the string "15-May-07". To apply format to a date use:
| >
| > Me.tbDayNo.Format="dd-mmm-yy"
| >
| > Regards
| > Jacob
| >
| >
| > | > | Cheese, I do have a problem with this, the date format should be
| > 12-May-07
| > | but when I use this control to change the date I am getting 12/5/2007,
I
| > | have tried this ,but not successful.............Thanks Bob
| > |
| > | Me.tbDayNo = DateAdd("d", 1, Me.tbDayNo)
| > | tbDayNo.value = Format("dd-mmm-yy")
| > |
| > | | > | > Hi Bob,
| > | >
| > | > Assumming you want to increase the date in the same text box where
the
| > | > date
| > | > appears:
| > | > ____________
| > | >
| > | > Sub cmdDatePush_click()
| > | >
| > | > Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)
| > | >
| > | > End Sub
| > | > ____________
| > | >
| > | > You'll need to add an error handler, as per standard operating
| > | > procedure...
| > | >
| > | > Hope that helps,
| > | > CW
| > | >
| > | > "Bob V" wrote:
| > | >
| > | >>
| > | >>
| > | >> If I had a Button what On Click code would I need to increase the
| > date
| > 1
| > | >> day
| > | >> The text box [tbStartDate1]
| > | >> Thanks for any help.....Bob
| > | >>
| > | >>
| > | >>
| > |
| > |
| >
| >
|
|
 
Thanks Jacob, But not quiet it, I have this code on a control next to my
date box [tbDateNo] but if I click the Control and there is no date in
[tbDateNo] I get error [Type Mismatch] so I wanted to -1 one day form Now()
or maybe should I have a error message MsgBox "This does not contain a
date!"
Thanks Bob

Private Sub Command242_Click()
Me.tbDayNo = DateAdd("d", -1, Me.tbDayNo)

tbDayNo.value = Format([tbDayNo], "dd-mmm-yy")
End Sub
JK said:
If I understand you correctly you want yesterdays date if tbDayNo is
blank.
That being the case:

1. Set the default of the field (in table design) to:
Date()-1

2. To "catch" blank dates already in the table use the Current Event:

If Not Me.NewRecord then
Me.tbDayNo=IIf(Nz(Me.tbDayNo,0)=0,Date-1,Me.tbDayNo)
End If

3. In the AfterUpdate event of the field:
Me.tbDayNo=IIf(Nz(Me.tbDayno,0)=0,Date-1,Me.tbDayNo)

Regards
Jacob


| Me.tbDayNo = DateAdd("d", -1, Me.tbDayNo)
|
| tbDayNo.value = Format([tbDayNo], "dd-mmm-yy")
|
| Thanks Jacob fixed it with this code
| But Can I have an error catch on it
| If tbDayNo = "" -1 , Now
| Meaning if tbDayNo is Blank -1 from Now Date
| Does that make sense! ;)
| Regards Bob
|
| | > Bob,
| >
| > The Format() function produces a *string* - Format(Date,"dd-mmm-yy")
will
| > produce the string "15-May-07". To apply format to a date use:
| >
| > Me.tbDayNo.Format="dd-mmm-yy"
| >
| > Regards
| > Jacob
| >
| >
| > | > | Cheese, I do have a problem with this, the date format should be
| > 12-May-07
| > | but when I use this control to change the date I am getting
12/5/2007,
I
| > | have tried this ,but not successful.............Thanks Bob
| > |
| > | Me.tbDayNo = DateAdd("d", 1, Me.tbDayNo)
| > | tbDayNo.value = Format("dd-mmm-yy")
| > |
message
| > | | > | > Hi Bob,
| > | >
| > | > Assumming you want to increase the date in the same text box where
the
| > | > date
| > | > appears:
| > | > ____________
| > | >
| > | > Sub cmdDatePush_click()
| > | >
| > | > Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)
| > | >
| > | > End Sub
| > | > ____________
| > | >
| > | > You'll need to add an error handler, as per standard operating
| > | > procedure...
| > | >
| > | > Hope that helps,
| > | > CW
| > | >
| > | > "Bob V" wrote:
| > | >
| > | >>
| > | >>
| > | >> If I had a Button what On Click code would I need to increase the
| > date
| > 1
| > | >> day
| > | >> The text box [tbStartDate1]
| > | >> Thanks for any help.....Bob
| > | >>
| > | >>
| > | >>
| > |
| > |
| >
| >
|
|
 
Thanks Jacob, But not quiet it, I have this code on a control next to my
date box [tbDateNo] but if I click the Control and there is no date in
[tbDateNo] I get error [Type Mismatch] so I wanted to -1 one day form Now()

Now() does NOT mean "today's date". It means "today's date and time accurate
to microseconds". Do you really want the textbox to contain
#07/13/2007 11:01:05pm#? Or do you want it to contain #07/13/2007#?
The Date() function returns a date value with midnight (00:00:00) as its time
portion.
or maybe should I have a error message MsgBox "This does not contain a
date!"
Thanks Bob

Private Sub Command242_Click()
Me.tbDayNo = DateAdd("d", -1, Me.tbDayNo)

tbDayNo.value = Format([tbDayNo], "dd-mmm-yy")
End Sub

Try

Me.tbDayNo = DateAdd("d", -1, NZ(Me.tbDayNo, Date()))

Note that clicking this button repeatedly will just keep subtracting one day
from the value in tbDayNo - it's not clear quite what you want to happen when
the date field is NOT blank.

John W. Vinson [MVP]
 
Bob,

1. Are we talking about a text box on a form? If so, unless you have
specified a default value for it, it will *always* be Null when you open the
form - are you aware of it?

2. The way your sub is now, you are subtracting 1 day from [tbDayNo] *and*
converting it into a *string*. This means that you will get mismatch error
if you click the button for the second time even when you have a value in
the text box because you cannot perform calculation on a string?

Remove 'tbDayNo.value = Format([tbDayNo], "dd-mmm-yy")' and use the format
property on the text box in the form instead.

3. To avoid calculating on Null value use the Nz() function:
Me.tbDayNo = DateAdd("d", -1, Nz(Me.tbDayNo,Date))

Regards
Jacob




| Thanks Jacob, But not quiet it, I have this code on a control next to my
| date box [tbDateNo] but if I click the Control and there is no date in
| [tbDateNo] I get error [Type Mismatch] so I wanted to -1 one day form
Now()
| or maybe should I have a error message MsgBox "This does not contain a
| date!"
| Thanks Bob
|
| Private Sub Command242_Click()
| Me.tbDayNo = DateAdd("d", -1, Me.tbDayNo)
|
| tbDayNo.value = Format([tbDayNo], "dd-mmm-yy")
| End Sub
| | > If I understand you correctly you want yesterdays date if tbDayNo is
| > blank.
| > That being the case:
| >
| > 1. Set the default of the field (in table design) to:
| > Date()-1
| >
| > 2. To "catch" blank dates already in the table use the Current Event:
| >
| > If Not Me.NewRecord then
| > Me.tbDayNo=IIf(Nz(Me.tbDayNo,0)=0,Date-1,Me.tbDayNo)
| > End If
| >
| > 3. In the AfterUpdate event of the field:
| > Me.tbDayNo=IIf(Nz(Me.tbDayno,0)=0,Date-1,Me.tbDayNo)
| >
| > Regards
| > Jacob
| >
| >
| > | > | Me.tbDayNo = DateAdd("d", -1, Me.tbDayNo)
| > |
| > | tbDayNo.value = Format([tbDayNo], "dd-mmm-yy")
| > |
| > | Thanks Jacob fixed it with this code
| > | But Can I have an error catch on it
| > | If tbDayNo = "" -1 , Now
| > | Meaning if tbDayNo is Blank -1 from Now Date
| > | Does that make sense! ;)
| > | Regards Bob
| > |
| > | | > | > Bob,
| > | >
| > | > The Format() function produces a *string* - Format(Date,"dd-mmm-yy")
| > will
| > | > produce the string "15-May-07". To apply format to a date use:
| > | >
| > | > Me.tbDayNo.Format="dd-mmm-yy"
| > | >
| > | > Regards
| > | > Jacob
| > | >
| > | >
| > | > | > | > | Cheese, I do have a problem with this, the date format should be
| > | > 12-May-07
| > | > | but when I use this control to change the date I am getting
| > 12/5/2007,
| > I
| > | > | have tried this ,but not successful.............Thanks Bob
| > | > |
| > | > | Me.tbDayNo = DateAdd("d", 1, Me.tbDayNo)
| > | > | tbDayNo.value = Format("dd-mmm-yy")
| > | > |
| > message
| > | > | | > | > | > Hi Bob,
| > | > | >
| > | > | > Assumming you want to increase the date in the same text box
where
| > the
| > | > | > date
| > | > | > appears:
| > | > | > ____________
| > | > | >
| > | > | > Sub cmdDatePush_click()
| > | > | >
| > | > | > Me.tbStartDate1 = DateAdd("d", 1, Me.tbStartDate1)
| > | > | >
| > | > | > End Sub
| > | > | > ____________
| > | > | >
| > | > | > You'll need to add an error handler, as per standard operating
| > | > | > procedure...
| > | > | >
| > | > | > Hope that helps,
| > | > | > CW
| > | > | >
| > | > | > "Bob V" wrote:
| > | > | >
| > | > | >>
| > | > | >>
| > | > | >> If I had a Button what On Click code would I need to increase
the
| > | > date
| > | > 1
| > | > | >> day
| > | > | >> The text box [tbStartDate1]
| > | > | >> Thanks for any help.....Bob
| > | > | >>
| > | > | >>
| > | > | >>
| > | > |
| > | > |
| > | >
| > | >
| > |
| > |
| >
| >
|
|
 

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

Similar Threads


Back
Top