Date Incruments 
Author Message
 Date Incruments

Hi,

I have a form with two fields, BeginDate and EndDate. The BeginDate starts
on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the following
code to calculate these date fields. What I want is when I click on
Command47 control, I want the BeginDate and EndDate to advance by a week
(7days). I appreciate you help in advance.

Private Sub Command47_Click()
Dim begindate As Date
Dim enddate As Date

    DoCmd.GoToRecord , , acNewRec
    Text0.SetFocus
    begindate = DateAdd("ww", 0, #1/1/2001#)
    enddate = DateAdd("ww", 0, #1/1/2001#) + 7
    begintext.Value = begindate
    endtext.Value = enddate

End Sub



Thu, 20 Nov 2003 22:38:44 GMT  
 Date Incruments
First, I'd like to point out that a date constant can be assigned directly to a date
variable like this

    begindate = #1/1/2001#

and that if you use the DateAdd function, you can include your increment within the
function like this

    begindate = DateAdd("ww", 1, #1/1/2001#)

for adding one week or

    begindate = DateAdd("d", 7, #1/1/2001#)

for adding seven days (both yielding the same result). Now, using your code structure ...

    Dim begindate As Date
    Dim enddate As Date

    DoCmd.GoToRecord , , acNewRec
    Text0.SetFocus
    If begintext.Value = "" Then
      begindate = #1/1/2001#
    Else
      begindate = DateAdd("d", 7, CDate(begintext.Value))
    End If
    enddate = DateAdd("d", 7, begindate)
    begintext.Value = begindate
    endtext.Value = enddate

Here I have assumed that begintext.Value is a text field that will contain the empty
string initially (and so assign #1/1/2001# to begindate the first time the Command47
button is pressed. After that, if begintext.Value contains a date string, it is converted
to a date value and 7 days are added to it. The enddate is always calculated by adding 7
days to the begindate. Hence, both dates should advance 7 days each time the Command47
button is pressed.

Rick


Quote:
> Hi,

> I have a form with two fields, BeginDate and EndDate. The BeginDate starts
> on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the following
> code to calculate these date fields. What I want is when I click on
> Command47 control, I want the BeginDate and EndDate to advance by a week
> (7days). I appreciate you help in advance.

> Private Sub Command47_Click()
> Dim begindate As Date
> Dim enddate As Date

>     DoCmd.GoToRecord , , acNewRec
>     Text0.SetFocus
>     begindate = DateAdd("ww", 0, #1/1/2001#)
>     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
>     begintext.Value = begindate
>     endtext.Value = enddate

> End Sub



Thu, 20 Nov 2003 23:35:06 GMT  
 Date Incruments
Rick,

Thank you for the quick response. Your assumption that begintext.Value is a
text field that will contain the empty is correct, and you understand
exactly what I want to accomplish. I've applied the code you provided, but I
get a run time error (94) when I run the program "Invalid use of Null". The
debug windows shows that CDate(begintext.Value) =<Invalid use of Null>
Even if I change the Null value in If begintext.Value = "" to a date, it
still gives the same error. I'm not really familiar with the CDATE function.
Addtionally, looking at the code, I don't see where the Null value is coming
from because we're using Empty string....

Thanks


Quote:
> Hi,

> I have a form with two fields, BeginDate and EndDate. The BeginDate starts
> on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the
following
> code to calculate these date fields. What I want is when I click on
> Command47 control, I want the BeginDate and EndDate to advance by a week
> (7days). I appreciate you help in advance.

> Private Sub Command47_Click()
> Dim begindate As Date
> Dim enddate As Date

>     DoCmd.GoToRecord , , acNewRec
>     Text0.SetFocus
>     begindate = DateAdd("ww", 0, #1/1/2001#)
>     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
>     begintext.Value = begindate
>     endtext.Value = enddate

> End Sub



Fri, 21 Nov 2003 03:16:21 GMT  
 Date Incruments
Rick,

Thank you for the quick response. Your assumption that begintext.Value is a
text field that will contain the empty is correct, and you understand
exactly what I want to accomplish. I've applied the code you provided, but I
get a run time error (94) when I run the program "Invalid use of Null". The
debug windows shows that CDate(begintext.Value) =<Invalid use of Null>
Even if I change the Null value in If begintext.Value = "" to a date, it
still gives the same error. I'm not really familiar with the CDATE function.

Thank you,

Quote:
> string initially



Quote:
> First, I'd like to point out that a date constant can be assigned directly
to a date
> variable like this

>     begindate = #1/1/2001#

> and that if you use the DateAdd function, you can include your increment
within the
> function like this

>     begindate = DateAdd("ww", 1, #1/1/2001#)

> for adding one week or

>     begindate = DateAdd("d", 7, #1/1/2001#)

> for adding seven days (both yielding the same result). Now, using your
code structure ...

>     Dim begindate As Date
>     Dim enddate As Date

>     DoCmd.GoToRecord , , acNewRec
>     Text0.SetFocus
>     If begintext.Value = "" Then
>       begindate = #1/1/2001#
>     Else
>       begindate = DateAdd("d", 7, CDate(begintext.Value))
>     End If
>     enddate = DateAdd("d", 7, begindate)
>     begintext.Value = begindate
>     endtext.Value = enddate

> Here I have assumed that begintext.Value is a text field that will contain
the empty
> string initially (and so assign #1/1/2001# to begindate the first time the
Command47
> button is pressed. After that, if begintext.Value contains a date string,
it is converted
> to a date value and 7 days are added to it. The enddate is always

calculated by adding 7

- Show quoted text -

Quote:
> days to the begindate. Hence, both dates should advance 7 days each time
the Command47
> button is pressed.

> Rick



> > Hi,

> > I have a form with two fields, BeginDate and EndDate. The BeginDate
starts
> > on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the
following
> > code to calculate these date fields. What I want is when I click on
> > Command47 control, I want the BeginDate and EndDate to advance by a week
> > (7days). I appreciate you help in advance.

> > Private Sub Command47_Click()
> > Dim begindate As Date
> > Dim enddate As Date

> >     DoCmd.GoToRecord , , acNewRec
> >     Text0.SetFocus
> >     begindate = DateAdd("ww", 0, #1/1/2001#)
> >     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
> >     begintext.Value = begindate
> >     endtext.Value = enddate

> > End Sub



Fri, 21 Nov 2003 02:43:18 GMT  
 Date Incruments
One more thing, looking at the code, I don't see where the Null value is
coming from because we're using Empty string....


Quote:
> Hi,

> I have a form with two fields, BeginDate and EndDate. The BeginDate starts
> on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the
following
> code to calculate these date fields. What I want is when I click on
> Command47 control, I want the BeginDate and EndDate to advance by a week
> (7days). I appreciate you help in advance.

> Private Sub Command47_Click()
> Dim begindate As Date
> Dim enddate As Date

>     DoCmd.GoToRecord , , acNewRec
>     Text0.SetFocus
>     begindate = DateAdd("ww", 0, #1/1/2001#)
>     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
>     begintext.Value = begindate
>     endtext.Value = enddate

> End Sub



Fri, 21 Nov 2003 02:46:48 GMT  
 Date Incruments
Try changing this line

     If begintext.Value = "" Then

to this

     If IsNull(begintext.Value) Then

and see if that works. (My assumption of what begintext is may have been incorrect.)

Rick


Quote:
> Rick,

> Thank you for the quick response. Your assumption that begintext.Value is a
> text field that will contain the empty is correct, and you understand
> exactly what I want to accomplish. I've applied the code you provided, but I
> get a run time error (94) when I run the program "Invalid use of Null". The
> debug windows shows that CDate(begintext.Value) =<Invalid use of Null>
> Even if I change the Null value in If begintext.Value = "" to a date, it
> still gives the same error. I'm not really familiar with the CDATE function.

> Thank you,

> > string initially


> > First, I'd like to point out that a date constant can be assigned directly
> to a date
> > variable like this

> >     begindate = #1/1/2001#

> > and that if you use the DateAdd function, you can include your increment
> within the
> > function like this

> >     begindate = DateAdd("ww", 1, #1/1/2001#)

> > for adding one week or

> >     begindate = DateAdd("d", 7, #1/1/2001#)

> > for adding seven days (both yielding the same result). Now, using your
> code structure ...

> >     Dim begindate As Date
> >     Dim enddate As Date

> >     DoCmd.GoToRecord , , acNewRec
> >     Text0.SetFocus
> >     If begintext.Value = "" Then
> >       begindate = #1/1/2001#
> >     Else
> >       begindate = DateAdd("d", 7, CDate(begintext.Value))
> >     End If
> >     enddate = DateAdd("d", 7, begindate)
> >     begintext.Value = begindate
> >     endtext.Value = enddate

> > Here I have assumed that begintext.Value is a text field that will contain
> the empty
> > string initially (and so assign #1/1/2001# to begindate the first time the
> Command47
> > button is pressed. After that, if begintext.Value contains a date string,
> it is converted
> > to a date value and 7 days are added to it. The enddate is always
> calculated by adding 7
> > days to the begindate. Hence, both dates should advance 7 days each time
> the Command47
> > button is pressed.

> > Rick



> > > Hi,

> > > I have a form with two fields, BeginDate and EndDate. The BeginDate
> starts
> > > on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the
> following
> > > code to calculate these date fields. What I want is when I click on
> > > Command47 control, I want the BeginDate and EndDate to advance by a week
> > > (7days). I appreciate you help in advance.

> > > Private Sub Command47_Click()
> > > Dim begindate As Date
> > > Dim enddate As Date

> > >     DoCmd.GoToRecord , , acNewRec
> > >     Text0.SetFocus
> > >     begindate = DateAdd("ww", 0, #1/1/2001#)
> > >     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
> > >     begintext.Value = begindate
> > >     endtext.Value = enddate

> > > End Sub



Fri, 21 Nov 2003 03:46:04 GMT  
 Date Incruments
Changing the line to If IsNull(begintext.Value) Then took care of the error
message and populates the date, but it does not advance it 7 days...driving
my crazy LOL

Thanks for your help.


Quote:
> Try changing this line

>      If begintext.Value = "" Then

> to this

>      If IsNull(begintext.Value) Then

> and see if that works. (My assumption of what begintext is may have been
incorrect.)

> Rick



> > Rick,

> > Thank you for the quick response. Your assumption that begintext.Value
is a
> > text field that will contain the empty is correct, and you understand
> > exactly what I want to accomplish. I've applied the code you provided,
but I
> > get a run time error (94) when I run the program "Invalid use of Null".
The
> > debug windows shows that CDate(begintext.Value) =<Invalid use of Null>
> > Even if I change the Null value in If begintext.Value = "" to a date, it
> > still gives the same error. I'm not really familiar with the CDATE
function.

> > Thank you,

> > > string initially


> > > First, I'd like to point out that a date constant can be assigned
directly
> > to a date
> > > variable like this

> > >     begindate = #1/1/2001#

> > > and that if you use the DateAdd function, you can include your
increment
> > within the
> > > function like this

> > >     begindate = DateAdd("ww", 1, #1/1/2001#)

> > > for adding one week or

> > >     begindate = DateAdd("d", 7, #1/1/2001#)

> > > for adding seven days (both yielding the same result). Now, using your
> > code structure ...

> > >     Dim begindate As Date
> > >     Dim enddate As Date

> > >     DoCmd.GoToRecord , , acNewRec
> > >     Text0.SetFocus
> > >     If begintext.Value = "" Then
> > >       begindate = #1/1/2001#
> > >     Else
> > >       begindate = DateAdd("d", 7, CDate(begintext.Value))
> > >     End If
> > >     enddate = DateAdd("d", 7, begindate)
> > >     begintext.Value = begindate
> > >     endtext.Value = enddate

> > > Here I have assumed that begintext.Value is a text field that will
contain
> > the empty
> > > string initially (and so assign #1/1/2001# to begindate the first time
the
> > Command47
> > > button is pressed. After that, if begintext.Value contains a date
string,
> > it is converted
> > > to a date value and 7 days are added to it. The enddate is always
> > calculated by adding 7
> > > days to the begindate. Hence, both dates should advance 7 days each
time
> > the Command47
> > > button is pressed.

> > > Rick



> > > > Hi,

> > > > I have a form with two fields, BeginDate and EndDate. The BeginDate
> > starts
> > > > on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the
> > following
> > > > code to calculate these date fields. What I want is when I click on
> > > > Command47 control, I want the BeginDate and EndDate to advance by a
week
> > > > (7days). I appreciate you help in advance.

> > > > Private Sub Command47_Click()
> > > > Dim begindate As Date
> > > > Dim enddate As Date

> > > >     DoCmd.GoToRecord , , acNewRec
> > > >     Text0.SetFocus
> > > >     begindate = DateAdd("ww", 0, #1/1/2001#)
> > > >     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
> > > >     begintext.Value = begindate
> > > >     endtext.Value = enddate

> > > > End Sub



Fri, 21 Nov 2003 04:52:58 GMT  
 Date Incruments
Changing the line to If IsNull(begintext.Value) Then took care of the error
message and populates the date, but it does not advance it 7 days...driving
my crazy LOL

Thanks for your help.


Quote:
> Try changing this line

>      If begintext.Value = "" Then

> to this

>      If IsNull(begintext.Value) Then

> and see if that works. (My assumption of what begintext is may have been
incorrect.)

> Rick



> > Rick,

> > Thank you for the quick response. Your assumption that begintext.Value
is a
> > text field that will contain the empty is correct, and you understand
> > exactly what I want to accomplish. I've applied the code you provided,
but I
> > get a run time error (94) when I run the program "Invalid use of Null".
The
> > debug windows shows that CDate(begintext.Value) =<Invalid use of Null>
> > Even if I change the Null value in If begintext.Value = "" to a date, it
> > still gives the same error. I'm not really familiar with the CDATE
function.

> > Thank you,

> > > string initially


> > > First, I'd like to point out that a date constant can be assigned
directly
> > to a date
> > > variable like this

> > >     begindate = #1/1/2001#

> > > and that if you use the DateAdd function, you can include your
increment
> > within the
> > > function like this

> > >     begindate = DateAdd("ww", 1, #1/1/2001#)

> > > for adding one week or

> > >     begindate = DateAdd("d", 7, #1/1/2001#)

> > > for adding seven days (both yielding the same result). Now, using your
> > code structure ...

> > >     Dim begindate As Date
> > >     Dim enddate As Date

> > >     DoCmd.GoToRecord , , acNewRec
> > >     Text0.SetFocus
> > >     If begintext.Value = "" Then
> > >       begindate = #1/1/2001#
> > >     Else
> > >       begindate = DateAdd("d", 7, CDate(begintext.Value))
> > >     End If
> > >     enddate = DateAdd("d", 7, begindate)
> > >     begintext.Value = begindate
> > >     endtext.Value = enddate

> > > Here I have assumed that begintext.Value is a text field that will
contain
> > the empty
> > > string initially (and so assign #1/1/2001# to begindate the first time
the
> > Command47
> > > button is pressed. After that, if begintext.Value contains a date
string,
> > it is converted
> > > to a date value and 7 days are added to it. The enddate is always
> > calculated by adding 7
> > > days to the begindate. Hence, both dates should advance 7 days each
time
> > the Command47
> > > button is pressed.

> > > Rick



> > > > Hi,

> > > > I have a form with two fields, BeginDate and EndDate. The BeginDate
> > starts
> > > > on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the
> > following
> > > > code to calculate these date fields. What I want is when I click on
> > > > Command47 control, I want the BeginDate and EndDate to advance by a
week
> > > > (7days). I appreciate you help in advance.

> > > > Private Sub Command47_Click()
> > > > Dim begindate As Date
> > > > Dim enddate As Date

> > > >     DoCmd.GoToRecord , , acNewRec
> > > >     Text0.SetFocus
> > > >     begindate = DateAdd("ww", 0, #1/1/2001#)
> > > >     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
> > > >     begintext.Value = begindate
> > > >     endtext.Value = enddate

> > > > End Sub



Fri, 21 Nov 2003 04:52:58 GMT  
 Date Incruments
OK, let's try changing the last two lines to this

    begintext.Value = CStr(begindate)
    endtext.Value = CStr(enddate)

If this doesn't work, please tell me what kind of component (object?) is begintext and
endtext.

Rick


Quote:
> Changing the line to If IsNull(begintext.Value) Then took care of the error
> message and populates the date, but it does not advance it 7 days...driving
> my crazy LOL

> Thanks for your help.



> > Try changing this line

> >      If begintext.Value = "" Then

> > to this

> >      If IsNull(begintext.Value) Then

> > and see if that works. (My assumption of what begintext is may have been
> incorrect.)

> > Rick



> > > Rick,

> > > Thank you for the quick response. Your assumption that begintext.Value
> is a
> > > text field that will contain the empty is correct, and you understand
> > > exactly what I want to accomplish. I've applied the code you provided,
> but I
> > > get a run time error (94) when I run the program "Invalid use of Null".
> The
> > > debug windows shows that CDate(begintext.Value) =<Invalid use of Null>
> > > Even if I change the Null value in If begintext.Value = "" to a date, it
> > > still gives the same error. I'm not really familiar with the CDATE
> function.

> > > Thank you,

> > > > string initially


> > > > First, I'd like to point out that a date constant can be assigned
> directly
> > > to a date
> > > > variable like this

> > > >     begindate = #1/1/2001#

> > > > and that if you use the DateAdd function, you can include your
> increment
> > > within the
> > > > function like this

> > > >     begindate = DateAdd("ww", 1, #1/1/2001#)

> > > > for adding one week or

> > > >     begindate = DateAdd("d", 7, #1/1/2001#)

> > > > for adding seven days (both yielding the same result). Now, using your
> > > code structure ...

> > > >     Dim begindate As Date
> > > >     Dim enddate As Date

> > > >     DoCmd.GoToRecord , , acNewRec
> > > >     Text0.SetFocus
> > > >     If begintext.Value = "" Then
> > > >       begindate = #1/1/2001#
> > > >     Else
> > > >       begindate = DateAdd("d", 7, CDate(begintext.Value))
> > > >     End If
> > > >     enddate = DateAdd("d", 7, begindate)
> > > >     begintext.Value = begindate
> > > >     endtext.Value = enddate

> > > > Here I have assumed that begintext.Value is a text field that will
> contain
> > > the empty
> > > > string initially (and so assign #1/1/2001# to begindate the first time
> the
> > > Command47
> > > > button is pressed. After that, if begintext.Value contains a date
> string,
> > > it is converted
> > > > to a date value and 7 days are added to it. The enddate is always
> > > calculated by adding 7
> > > > days to the begindate. Hence, both dates should advance 7 days each
> time
> > > the Command47
> > > > button is pressed.

> > > > Rick



> > > > > Hi,

> > > > > I have a form with two fields, BeginDate and EndDate. The BeginDate
> > > starts
> > > > > on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the
> > > following
> > > > > code to calculate these date fields. What I want is when I click on
> > > > > Command47 control, I want the BeginDate and EndDate to advance by a
> week
> > > > > (7days). I appreciate you help in advance.

> > > > > Private Sub Command47_Click()
> > > > > Dim begindate As Date
> > > > > Dim enddate As Date

> > > > >     DoCmd.GoToRecord , , acNewRec
> > > > >     Text0.SetFocus
> > > > >     begindate = DateAdd("ww", 0, #1/1/2001#)
> > > > >     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
> > > > >     begintext.Value = begindate
> > > > >     endtext.Value = enddate

> > > > > End Sub



Fri, 21 Nov 2003 08:16:58 GMT  
 Date Incruments
The objects are text boxes. I did change the last two lines as you
suggested, but the date still does not advance. I appreciate all your help
on this.


Quote:
> OK, let's try changing the last two lines to this

>     begintext.Value = CStr(begindate)
>     endtext.Value = CStr(enddate)

> If this doesn't work, please tell me what kind of component (object?) is
begintext and
> endtext.

> Rick



> > Changing the line to If IsNull(begintext.Value) Then took care of the
error
> > message and populates the date, but it does not advance it 7
days...driving
> > my crazy LOL

> > Thanks for your help.



> > > Try changing this line

> > >      If begintext.Value = "" Then

> > > to this

> > >      If IsNull(begintext.Value) Then

> > > and see if that works. (My assumption of what begintext is may have
been
> > incorrect.)

> > > Rick



> > > > Rick,

> > > > Thank you for the quick response. Your assumption that
begintext.Value
> > is a
> > > > text field that will contain the empty is correct, and you
understand
> > > > exactly what I want to accomplish. I've applied the code you
provided,
> > but I
> > > > get a run time error (94) when I run the program "Invalid use of
Null".
> > The
> > > > debug windows shows that CDate(begintext.Value) =<Invalid use of
Null>
> > > > Even if I change the Null value in If begintext.Value = "" to a
date, it
> > > > still gives the same error. I'm not really familiar with the CDATE
> > function.

> > > > Thank you,

> > > > > string initially


> > > > > First, I'd like to point out that a date constant can be assigned
> > directly
> > > > to a date
> > > > > variable like this

> > > > >     begindate = #1/1/2001#

> > > > > and that if you use the DateAdd function, you can include your
> > increment
> > > > within the
> > > > > function like this

> > > > >     begindate = DateAdd("ww", 1, #1/1/2001#)

> > > > > for adding one week or

> > > > >     begindate = DateAdd("d", 7, #1/1/2001#)

> > > > > for adding seven days (both yielding the same result). Now, using
your
> > > > code structure ...

> > > > >     Dim begindate As Date
> > > > >     Dim enddate As Date

> > > > >     DoCmd.GoToRecord , , acNewRec
> > > > >     Text0.SetFocus
> > > > >     If begintext.Value = "" Then
> > > > >       begindate = #1/1/2001#
> > > > >     Else
> > > > >       begindate = DateAdd("d", 7, CDate(begintext.Value))
> > > > >     End If
> > > > >     enddate = DateAdd("d", 7, begindate)
> > > > >     begintext.Value = begindate
> > > > >     endtext.Value = enddate

> > > > > Here I have assumed that begintext.Value is a text field that will
> > contain
> > > > the empty
> > > > > string initially (and so assign #1/1/2001# to begindate the first
time
> > the
> > > > Command47
> > > > > button is pressed. After that, if begintext.Value contains a date
> > string,
> > > > it is converted
> > > > > to a date value and 7 days are added to it. The enddate is always
> > > > calculated by adding 7
> > > > > days to the begindate. Hence, both dates should advance 7 days
each
> > time
> > > > the Command47
> > > > > button is pressed.

> > > > > Rick



> > > > > > Hi,

> > > > > > I have a form with two fields, BeginDate and EndDate. The
BeginDate
> > > > starts
> > > > > > on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote
the
> > > > following
> > > > > > code to calculate these date fields. What I want is when I click
on
> > > > > > Command47 control, I want the BeginDate and EndDate to advance
by a
> > week
> > > > > > (7days). I appreciate you help in advance.

> > > > > > Private Sub Command47_Click()
> > > > > > Dim begindate As Date
> > > > > > Dim enddate As Date

> > > > > >     DoCmd.GoToRecord , , acNewRec
> > > > > >     Text0.SetFocus
> > > > > >     begindate = DateAdd("ww", 0, #1/1/2001#)
> > > > > >     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
> > > > > >     begintext.Value = begindate
> > > > > >     endtext.Value = enddate

> > > > > > End Sub



Fri, 21 Nov 2003 09:25:06 GMT  
 Date Incruments
If they are TextBoxes, then they don't have a Value property. Wherever you have .Value,
change that to .Text and then try it -- using this re-modified code (which I put together
now knowing they are TextBoxes)

    Dim begindate As Date
    Dim enddate As Date

    DoCmd.GoToRecord , , acNewRec
    Text0.SetFocus
    If begintext.Text = "" Then
      begindate = #1/1/2001#
    Else
      begindate = DateAdd("d", 7, CDate(begintext.Text))
    End If
    enddate = DateAdd("d", 7, begindate)
    begintext.Text = CStr(begindate)
    endtext.Text = Cstr(enddate)

Rick


Quote:
> The objects are text boxes. I did change the last two lines as you
> suggested, but the date still does not advance. I appreciate all your help
> on this.



> > OK, let's try changing the last two lines to this

> >     begintext.Value = CStr(begindate)
> >     endtext.Value = CStr(enddate)

> > If this doesn't work, please tell me what kind of component (object?) is
> begintext and
> > endtext.

> > Rick



> > > Changing the line to If IsNull(begintext.Value) Then took care of the
> error
> > > message and populates the date, but it does not advance it 7
> days...driving
> > > my crazy LOL

> > > Thanks for your help.



> > > > Try changing this line

> > > >      If begintext.Value = "" Then

> > > > to this

> > > >      If IsNull(begintext.Value) Then

> > > > and see if that works. (My assumption of what begintext is may have
> been
> > > incorrect.)

> > > > Rick



> > > > > Rick,

> > > > > Thank you for the quick response. Your assumption that
> begintext.Value
> > > is a
> > > > > text field that will contain the empty is correct, and you
> understand
> > > > > exactly what I want to accomplish. I've applied the code you
> provided,
> > > but I
> > > > > get a run time error (94) when I run the program "Invalid use of
> Null".
> > > The
> > > > > debug windows shows that CDate(begintext.Value) =<Invalid use of
> Null>
> > > > > Even if I change the Null value in If begintext.Value = "" to a
> date, it
> > > > > still gives the same error. I'm not really familiar with the CDATE
> > > function.

> > > > > Thank you,

> > > > > > string initially


> > > > > > First, I'd like to point out that a date constant can be assigned
> > > directly
> > > > > to a date
> > > > > > variable like this

> > > > > >     begindate = #1/1/2001#

> > > > > > and that if you use the DateAdd function, you can include your
> > > increment
> > > > > within the
> > > > > > function like this

> > > > > >     begindate = DateAdd("ww", 1, #1/1/2001#)

> > > > > > for adding one week or

> > > > > >     begindate = DateAdd("d", 7, #1/1/2001#)

> > > > > > for adding seven days (both yielding the same result). Now, using
> your
> > > > > code structure ...

> > > > > >     Dim begindate As Date
> > > > > >     Dim enddate As Date

> > > > > >     DoCmd.GoToRecord , , acNewRec
> > > > > >     Text0.SetFocus
> > > > > >     If begintext.Value = "" Then
> > > > > >       begindate = #1/1/2001#
> > > > > >     Else
> > > > > >       begindate = DateAdd("d", 7, CDate(begintext.Value))
> > > > > >     End If
> > > > > >     enddate = DateAdd("d", 7, begindate)
> > > > > >     begintext.Value = begindate
> > > > > >     endtext.Value = enddate

> > > > > > Here I have assumed that begintext.Value is a text field that will
> > > contain
> > > > > the empty
> > > > > > string initially (and so assign #1/1/2001# to begindate the first
> time
> > > the
> > > > > Command47
> > > > > > button is pressed. After that, if begintext.Value contains a date
> > > string,
> > > > > it is converted
> > > > > > to a date value and 7 days are added to it. The enddate is always
> > > > > calculated by adding 7
> > > > > > days to the begindate. Hence, both dates should advance 7 days
> each
> > > time
> > > > > the Command47
> > > > > > button is pressed.

> > > > > > Rick



> > > > > > > Hi,

> > > > > > > I have a form with two fields, BeginDate and EndDate. The
> BeginDate
> > > > > starts
> > > > > > > on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote
> the
> > > > > following
> > > > > > > code to calculate these date fields. What I want is when I click
> on
> > > > > > > Command47 control, I want the BeginDate and EndDate to advance
> by a
> > > week
> > > > > > > (7days). I appreciate you help in advance.

> > > > > > > Private Sub Command47_Click()
> > > > > > > Dim begindate As Date
> > > > > > > Dim enddate As Date

> > > > > > >     DoCmd.GoToRecord , , acNewRec
> > > > > > >     Text0.SetFocus
> > > > > > >     begindate = DateAdd("ww", 0, #1/1/2001#)
> > > > > > >     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
> > > > > > >     begintext.Value = begindate
> > > > > > >     endtext.Value = enddate

> > > > > > > End Sub



Fri, 21 Nov 2003 10:05:27 GMT  
 Date Incruments
Good, its driving me crazy, I give up...Your help is very much appreciated


Quote:
> Hi,

> I have a form with two fields, BeginDate and EndDate. The BeginDate starts
> on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the
following
> code to calculate these date fields. What I want is when I click on
> Command47 control, I want the BeginDate and EndDate to advance by a week
> (7days). I appreciate you help in advance.

> Private Sub Command47_Click()
> Dim begindate As Date
> Dim enddate As Date

>     DoCmd.GoToRecord , , acNewRec
>     Text0.SetFocus
>     begindate = DateAdd("ww", 0, #1/1/2001#)
>     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
>     begintext.Value = begindate
>     endtext.Value = enddate

> End Sub



Sat, 22 Nov 2003 09:43:42 GMT  
 Date Incruments
You may want to try the isDate() Function instead of isNull to test if it a
valid date:

Private Sub Command47_Click()
    If IsDate(Text1.Text) Then
        Text1.Text = DateAdd("ww", 1, CDate(Text1.Text))
    Else
        Text1.Text = Date
    End If
    Text2.Text = DateAdd("ww", 1, CDate(Text1.Text))
End Sub


Hi,

I have a form with two fields, BeginDate and EndDate. The BeginDate starts
on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the following
code to calculate these date fields. What I want is when I click on
Command47 control, I want the BeginDate and EndDate to advance by a week
(7days). I appreciate you help in advance.

Private Sub Command47_Click()
Dim begindate As Date
Dim enddate As Date

    DoCmd.GoToRecord , , acNewRec
    Text0.SetFocus
    begindate = DateAdd("ww", 0, #1/1/2001#)
    enddate = DateAdd("ww", 0, #1/1/2001#) + 7
    begintext.Value = begindate
    endtext.Value = enddate

End Sub



Sat, 22 Nov 2003 22:34:13 GMT  
 Date Incruments
With the help of one my team members, here is what we had to do to get
working. I thank you all for your help, we would not do it without all your
help.

Private Sub Command47_Click()

    Dim begindate As Date
    Dim enddate As Date
    Dim newbegindate
    Dim newenddate

    begintext.SetFocus
    If begintext.Text = "" Then
      newbegindate = "01/01/01"
    Else
      newbegindate = DateAdd("d", 7, DateValue(begintext.Text))
    End If
    newenddate = DateAdd("d", 6, newbegindate)
    DoCmd.GoToRecord , , acNewRec
    begintext.SetFocus
    begintext.Text = CStr(newbegindate)
    endtext.SetFocus
    endtext.Text = CStr(newenddate)

End Sub


Quote:
> Hi,

> I have a form with two fields, BeginDate and EndDate. The BeginDate starts
> on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the
following
> code to calculate these date fields. What I want is when I click on
> Command47 control, I want the BeginDate and EndDate to advance by a week
> (7days). I appreciate you help in advance.

> Private Sub Command47_Click()
> Dim begindate As Date
> Dim enddate As Date

>     DoCmd.GoToRecord , , acNewRec
>     Text0.SetFocus
>     begindate = DateAdd("ww", 0, #1/1/2001#)
>     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
>     begintext.Value = begindate
>     endtext.Value = enddate

> End Sub



Tue, 25 Nov 2003 00:22:53 GMT  
 Date Incruments
Again I would urge you to consider using isDate(textbox.text) rather than
textbox.text="" as a user may inadvertantly enter 02/30/2001 which will
cause an error when you attempt to add the dates


With the help of one my team members, here is what we had to do to get
working. I thank you all for your help, we would not do it without all your
help.

Private Sub Command47_Click()

    Dim begindate As Date
    Dim enddate As Date
    Dim newbegindate
    Dim newenddate

    begintext.SetFocus
    If begintext.Text = "" Then
      newbegindate = "01/01/01"
    Else
      newbegindate = DateAdd("d", 7, DateValue(begintext.Text))
    End If
    newenddate = DateAdd("d", 6, newbegindate)
    DoCmd.GoToRecord , , acNewRec
    begintext.SetFocus
    begintext.Text = CStr(newbegindate)
    endtext.SetFocus
    endtext.Text = CStr(newenddate)

End Sub


Quote:
> Hi,

> I have a form with two fields, BeginDate and EndDate. The BeginDate starts
> on 1/1/2001, and the EndDate is a week later 1/8/2001. I wrote the
following
> code to calculate these date fields. What I want is when I click on
> Command47 control, I want the BeginDate and EndDate to advance by a week
> (7days). I appreciate you help in advance.

> Private Sub Command47_Click()
> Dim begindate As Date
> Dim enddate As Date

>     DoCmd.GoToRecord , , acNewRec
>     Text0.SetFocus
>     begindate = DateAdd("ww", 0, #1/1/2001#)
>     enddate = DateAdd("ww", 0, #1/1/2001#) + 7
>     begintext.Value = begindate
>     endtext.Value = enddate

> End Sub



Tue, 25 Nov 2003 23:40:33 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. Date - date = date

2. Compare date in form with date/time in form with date/time in database

3. Dates dates dates

4. Dates, Dates, & More Dates

5. Date Difference to Return the most Current Date

6. Date/Time to date

7. VBA date query - not getting current date

8. Changing a Calculate field (Date) depending on Current date

9. ACC97:Date Conversion - Date to Double

10. Extracting the date out of a Date/Time field

11. Those Wierd Dates - Julian Dates

12. Converting Julian Date to Long Date

 

 
Powered by phpBB® Forum Software