# of days left

  • Thread starter Thread starter marc
  • Start date Start date
M

marc

I have 3 fields one of which is called Status, one called
Approved ECD and another called Time left to close. I
need to find out how to get the time left to close field
to place a number of days left till the date in the
approved ECD field IF the status field does not say
closed. If it does say closed I would like the time left
to close field to become empty or null. Below is what I
have:

Public Sub Status_Exit(Cancel As Integer)
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now(),
[Approved ECD])
End If
End Sub


Any help would be greatly appreciated.
 
I am not understanding what you want to do that is different from what you
have posted as your code? Can you elaborate, please?
 
This is what happens when I exit the status field. When
it says closed and I tab out of the field I get a number
that pops up in it. I want it to look at the status field
and if it sees anything but the word closed to then use
the datediff formula. If the word closed shows up in the
status field then I want it to leave the Time left to
close field empty.

-----Original Message-----
I am not understanding what you want to do that is different from what you
have posted as your code? Can you elaborate, please?

--
Ken Snell
<MS ACCESS MVP>

marc said:
I have 3 fields one of which is called Status, one called
Approved ECD and another called Time left to close. I
need to find out how to get the time left to close field
to place a number of days left till the date in the
approved ECD field IF the status field does not say
closed. If it does say closed I would like the time left
to close field to become empty or null. Below is what I
have:

Public Sub Status_Exit(Cancel As Integer)
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now(),
[Approved ECD])
End If
End Sub


Any help would be greatly appreciated.


.
 
Assuming that you're describing a control that is displaying the value of
the "total behind schedule" field, you can use a line of code similar to
what you used in your original code when the Status control was "Closed":

Me.Total_Behind_Schedule = Null

Here would be the modified code:

Public Sub Status_AfterUpdate()
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now(),
[Approved ECD])
Me.Total_Behind_Schedule = Null
End If
End Sub

--
Ken Snell
<MS ACCESS MVP>



Marc said:
Ken,
Something has come along the same line as this one. If
you can help that would be great. I got the code to work
for what I needed. Now i get a number in the time left to
close field and the total behind schedule field. Lets say
26 is the number. Time left to close say 26 and the total
behind schedule says -26. I want to put some code into
the database that tells it to null the field that is
negative.



Also,
When the Approved ECD fields date changes I would like
to see the numbers in the fields mentioned above to
change. How can I do this?



-----Original Message-----
Ken,
Thanks for the help. I don't know why but the code
would not work for the on exit but works just fine for the
after update. I thought the code should work that is
where I was getting confused. Again thanks for the help.
-----Original Message-----
But that is what I understand that your code is doing.
Is
it not working?
If not, try moving it to the AfterUpdate event of the Status field.

Sorry, but I am not understanding completely, I think.
--
Ken Snell
<MS ACCESS MVP>

This is what happens when I exit the status field. When
it says closed and I tab out of the field I get a number
that pops up in it. I want it to look at the status field
and if it sees anything but the word closed to then use
the datediff formula. If the word closed shows up in the
status field then I want it to leave the Time left to
close field empty.


-----Original Message-----
I am not understanding what you want to do that is
different from what you
have posted as your code? Can you elaborate, please?

--
Ken Snell
<MS ACCESS MVP>

I have 3 fields one of which is called Status, one
called
Approved ECD and another called Time left to
close.
I
need to find out how to get the time left to close field
to place a number of days left till the date in the
approved ECD field IF the status field does not say
closed. If it does say closed I would like the time
left
to close field to become empty or null. Below is what I
have:

Public Sub Status_Exit(Cancel As Integer)
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now (),
[Approved ECD])
End If
End Sub


Any help would be greatly appreciated.



.



.
.
 
-----Original Message-----
Assuming that you're describing a control that is displaying the value of
the "total behind schedule" field, you can use a line of code similar to
what you used in your original code when the Status control was "Closed":

Me.Total_Behind_Schedule = Null

Here would be the modified code:

Public Sub Status_AfterUpdate()
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now(),
[Approved ECD])
Me.Total_Behind_Schedule = Null
End If
End Sub

--
Ken Snell
<MS ACCESS MVP>



Marc said:
Ken,
Something has come along the same line as this one. If
you can help that would be great. I got the code to work
for what I needed. Now i get a number in the time left to
close field and the total behind schedule field. Lets say
26 is the number. Time left to close say 26 and the total
behind schedule says -26. I want to put some code into
the database that tells it to null the field that is
negative.



Also,
When the Approved ECD fields date changes I would like
to see the numbers in the fields mentioned above to
change. How can I do this?



-----Original Message-----
Ken,
Thanks for the help. I don't know why but the code
would not work for the on exit but works just fine for the
after update. I thought the code should work that is
where I was getting confused. Again thanks for the help.

-----Original Message-----
But that is what I understand that your code is doing. Is
it not working?

If not, try moving it to the AfterUpdate event of the
Status field.

Sorry, but I am not understanding completely, I think.
--
Ken Snell
<MS ACCESS MVP>

This is what happens when I exit the status field. When
it says closed and I tab out of the field I get a number
that pops up in it. I want it to look at the status
field
and if it sees anything but the word closed to then use
the datediff formula. If the word closed shows up in
the
status field then I want it to leave the Time left to
close field empty.


-----Original Message-----
I am not understanding what you want to do that is
different from what you
have posted as your code? Can you elaborate, please?

--
Ken Snell
<MS ACCESS MVP>

I have 3 fields one of which is called Status, one
called
Approved ECD and another called Time left to close.
I
need to find out how to get the time left to close
field
to place a number of days left till the date in the
approved ECD field IF the status field does not say
closed. If it does say closed I would like the time
left
to close field to become empty or null. Below is
what I
have:

Public Sub Status_Exit(Cancel As Integer)
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d",
Now
(),
[Approved ECD])
End If
End Sub


Any help would be greatly appreciated.



.



.

.


.
 
-----Original Message-----
Assuming that you're describing a control that is displaying the value of
the "total behind schedule" field, you can use a line of code similar to
what you used in your original code when the Status control was "Closed":

Me.Total_Behind_Schedule = Null

Here would be the modified code:

Public Sub Status_AfterUpdate()
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now(),
[Approved ECD])
Me.Total_Behind_Schedule = Null
End If
End Sub

--
Ken Snell
<MS ACCESS MVP>



Marc said:
Ken,
Something has come along the same line as this one. If
you can help that would be great. I got the code to work
for what I needed. Now i get a number in the time left to
close field and the total behind schedule field. Lets say
26 is the number. Time left to close say 26 and the total
behind schedule says -26. I want to put some code into
the database that tells it to null the field that is
negative.



Also,
When the Approved ECD fields date changes I would like
to see the numbers in the fields mentioned above to
change. How can I do this?



-----Original Message-----
Ken,
Thanks for the help. I don't know why but the code
would not work for the on exit but works just fine for the
after update. I thought the code should work that is
where I was getting confused. Again thanks for the help.

-----Original Message-----
But that is what I understand that your code is doing. Is
it not working?

If not, try moving it to the AfterUpdate event of the
Status field.

Sorry, but I am not understanding completely, I think.
--
Ken Snell
<MS ACCESS MVP>

This is what happens when I exit the status field. When
it says closed and I tab out of the field I get a number
that pops up in it. I want it to look at the status
field
and if it sees anything but the word closed to then use
the datediff formula. If the word closed shows up in
the
status field then I want it to leave the Time left to
close field empty.


-----Original Message-----
I am not understanding what you want to do that is
different from what you
have posted as your code? Can you elaborate, please?

--
Ken Snell
<MS ACCESS MVP>

I have 3 fields one of which is called Status, one
called
Approved ECD and another called Time left to close.
I
need to find out how to get the time left to close
field
to place a number of days left till the date in the
approved ECD field IF the status field does not say
closed. If it does say closed I would like the time
left
to close field to become empty or null. Below is
what I
have:

Public Sub Status_Exit(Cancel As Integer)
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d",
Now
(),
[Approved ECD])
End If
End Sub


Any help would be greatly appreciated.



.



.

.


.
 
Ken,
Let me tell you what I am trying to do. I have a
database in which I am tracking some taskings with. I
would like to show either how many days left till the
close of the particular task or how many days past the ECD
(estimated close date). This is where the time left to
close and the behind schedule fields come in. What I
would like to be able to do is have the above 2 fields
update automatically when and if the approved ECD field
changes. Since I placed the code under the AfterUpdate I
don't think it will up date unless the Status field is
touched. Is there an easy way of doing this?

I would also like to have the time left to close and
behind schedule fields to only show up they are positive
numbers. for example if the time left to close date shows
a positive number and the behind schedule date shows a
negative number then the behind schedule field will be
null. Is this possible to do as well?


-----Original Message-----
Assuming that you're describing a control that is displaying the value of
the "total behind schedule" field, you can use a line of code similar to
what you used in your original code when the Status control was "Closed":

Me.Total_Behind_Schedule = Null

Here would be the modified code:

Public Sub Status_AfterUpdate()
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now(),
[Approved ECD])
Me.Total_Behind_Schedule = Null
End If
End Sub

--
Ken Snell
<MS ACCESS MVP>



Marc said:
Ken,
Something has come along the same line as this one. If
you can help that would be great. I got the code to work
for what I needed. Now i get a number in the time left to
close field and the total behind schedule field. Lets say
26 is the number. Time left to close say 26 and the total
behind schedule says -26. I want to put some code into
the database that tells it to null the field that is
negative.



Also,
When the Approved ECD fields date changes I would like
to see the numbers in the fields mentioned above to
change. How can I do this?



-----Original Message-----
Ken,
Thanks for the help. I don't know why but the code
would not work for the on exit but works just fine for the
after update. I thought the code should work that is
where I was getting confused. Again thanks for the help.

-----Original Message-----
But that is what I understand that your code is doing. Is
it not working?

If not, try moving it to the AfterUpdate event of the
Status field.

Sorry, but I am not understanding completely, I think.
--
Ken Snell
<MS ACCESS MVP>

This is what happens when I exit the status field. When
it says closed and I tab out of the field I get a number
that pops up in it. I want it to look at the status
field
and if it sees anything but the word closed to then use
the datediff formula. If the word closed shows up in
the
status field then I want it to leave the Time left to
close field empty.


-----Original Message-----
I am not understanding what you want to do that is
different from what you
have posted as your code? Can you elaborate, please?

--
Ken Snell
<MS ACCESS MVP>

I have 3 fields one of which is called Status, one
called
Approved ECD and another called Time left to close.
I
need to find out how to get the time left to close
field
to place a number of days left till the date in the
approved ECD field IF the status field does not say
closed. If it does say closed I would like the time
left
to close field to become empty or null. Below is
what I
have:

Public Sub Status_Exit(Cancel As Integer)
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d",
Now
(),
[Approved ECD])
End If
End Sub


Any help would be greatly appreciated.



.



.

.


.
 
How can the value of "Approved ECD" field change? Does it change when a user
changes it? When you open the form on a new day (different "current date")?
Does some other event change it? You need to determine what is happening
when it "changes" if you want to "capture" that change so that you can do
something in the other controls.

Otherwise, you need to recalculate the values of Total_Behind_Schedule and
Time_Left_to_Close_Date controls whenever you open the form or change to a
different record. Then you don't need to "capture" the change of Approved
ECD. Can you identify an expression that would result in the correct
calculation each time? Then you could use that expression as the control
source for the controls.

I am having difficulty visualizing your form and table setup -- that is
hampering my ability to "see" a possible solution. I hope you're not trying
to store the values of Total_Behind_Schedule and Time_Left_to_Close_Date
controls in a table -- if they can be calculated, then you should calculate
them when you want to see them. Then my suggestion of using an expression as
the control source for these two controls makes even better sense.

As for having them show up only if positive, your expression could utilize a
statement similar to this; for example,
IIf([Status] <> "Closed", IIf(DateDiff("d", Now(), [Approved ECD]) >
0, DateDiff("d", Now(), [Approved ECD]), Null), Null)


--
Ken Snell
<MS ACCESS MVP>

marc said:
Ken,
Let me tell you what I am trying to do. I have a
database in which I am tracking some taskings with. I
would like to show either how many days left till the
close of the particular task or how many days past the ECD
(estimated close date). This is where the time left to
close and the behind schedule fields come in. What I
would like to be able to do is have the above 2 fields
update automatically when and if the approved ECD field
changes. Since I placed the code under the AfterUpdate I
don't think it will up date unless the Status field is
touched. Is there an easy way of doing this?

I would also like to have the time left to close and
behind schedule fields to only show up they are positive
numbers. for example if the time left to close date shows
a positive number and the behind schedule date shows a
negative number then the behind schedule field will be
null. Is this possible to do as well?


-----Original Message-----
Assuming that you're describing a control that is displaying the value of
the "total behind schedule" field, you can use a line of code similar to
what you used in your original code when the Status control was "Closed":

Me.Total_Behind_Schedule = Null

Here would be the modified code:

Public Sub Status_AfterUpdate()
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now(),
[Approved ECD])
Me.Total_Behind_Schedule = Null
End If
End Sub

--
Ken Snell
<MS ACCESS MVP>



Marc said:
Ken,
Something has come along the same line as this one. If
you can help that would be great. I got the code to work
for what I needed. Now i get a number in the time left to
close field and the total behind schedule field. Lets say
26 is the number. Time left to close say 26 and the total
behind schedule says -26. I want to put some code into
the database that tells it to null the field that is
negative.



Also,
When the Approved ECD fields date changes I would like
to see the numbers in the fields mentioned above to
change. How can I do this?




-----Original Message-----
Ken,
Thanks for the help. I don't know why but the code
would not work for the on exit but works just fine for
the
after update. I thought the code should work that is
where I was getting confused. Again thanks for the help.

-----Original Message-----
But that is what I understand that your code is doing.
Is
it not working?

If not, try moving it to the AfterUpdate event of the
Status field.

Sorry, but I am not understanding completely, I think.
--
Ken Snell
<MS ACCESS MVP>

This is what happens when I exit the status field.
When
it says closed and I tab out of the field I get a
number
that pops up in it. I want it to look at the status
field
and if it sees anything but the word closed to then use
the datediff formula. If the word closed shows up in
the
status field then I want it to leave the Time left to
close field empty.


-----Original Message-----
I am not understanding what you want to do that is
different from what you
have posted as your code? Can you elaborate, please?

--
Ken Snell
<MS ACCESS MVP>

I have 3 fields one of which is called Status, one
called
Approved ECD and another called Time left to
close.
I
need to find out how to get the time left to close
field
to place a number of days left till the date in the
approved ECD field IF the status field does not say
closed. If it does say closed I would like the time
left
to close field to become empty or null. Below is
what I
have:

Public Sub Status_Exit(Cancel As Integer)
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now
(),
[Approved ECD])
End If
End Sub


Any help would be greatly appreciated.



.



.

.


.
 
Is there anyway I can maybe send you a copy of what I have
so you can look at it?
-----Original Message-----
How can the value of "Approved ECD" field change? Does it change when a user
changes it? When you open the form on a new day (different "current date")?
Does some other event change it? You need to determine what is happening
when it "changes" if you want to "capture" that change so that you can do
something in the other controls.

Otherwise, you need to recalculate the values of Total_Behind_Schedule and
Time_Left_to_Close_Date controls whenever you open the form or change to a
different record. Then you don't need to "capture" the change of Approved
ECD. Can you identify an expression that would result in the correct
calculation each time? Then you could use that expression as the control
source for the controls.

I am having difficulty visualizing your form and table setup -- that is
hampering my ability to "see" a possible solution. I hope you're not trying
to store the values of Total_Behind_Schedule and Time_Left_to_Close_Date
controls in a table -- if they can be calculated, then you should calculate
them when you want to see them. Then my suggestion of using an expression as
the control source for these two controls makes even better sense.

As for having them show up only if positive, your expression could utilize a
statement similar to this; for example,
IIf([Status] <> "Closed", IIf(DateDiff("d", Now (), [Approved ECD]) >
0, DateDiff("d", Now(), [Approved ECD]), Null), Null)


--
Ken Snell
<MS ACCESS MVP>

marc said:
Ken,
Let me tell you what I am trying to do. I have a
database in which I am tracking some taskings with. I
would like to show either how many days left till the
close of the particular task or how many days past the ECD
(estimated close date). This is where the time left to
close and the behind schedule fields come in. What I
would like to be able to do is have the above 2 fields
update automatically when and if the approved ECD field
changes. Since I placed the code under the AfterUpdate I
don't think it will up date unless the Status field is
touched. Is there an easy way of doing this?

I would also like to have the time left to close and
behind schedule fields to only show up they are positive
numbers. for example if the time left to close date shows
a positive number and the behind schedule date shows a
negative number then the behind schedule field will be
null. Is this possible to do as well?


-----Original Message-----
Assuming that you're describing a control that is displaying the value of
the "total behind schedule" field, you can use a line
of
code similar to
what you used in your original code when the Status control was "Closed":

Me.Total_Behind_Schedule = Null

Here would be the modified code:

Public Sub Status_AfterUpdate()
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now(),
[Approved ECD])
Me.Total_Behind_Schedule = Null
End If
End Sub

--
Ken Snell
<MS ACCESS MVP>



Ken,
Something has come along the same line as this one. If
you can help that would be great. I got the code to work
for what I needed. Now i get a number in the time
left
to
close field and the total behind schedule field.
Lets
say
26 is the number. Time left to close say 26 and the total
behind schedule says -26. I want to put some code into
the database that tells it to null the field that is
negative.



Also,
When the Approved ECD fields date changes I would like
to see the numbers in the fields mentioned above to
change. How can I do this?




-----Original Message-----
Ken,
Thanks for the help. I don't know why but the code
would not work for the on exit but works just fine for
the
after update. I thought the code should work that is
where I was getting confused. Again thanks for the help.

-----Original Message-----
But that is what I understand that your code is doing.
Is
it not working?

If not, try moving it to the AfterUpdate event of the
Status field.

Sorry, but I am not understanding completely, I think.
--
Ken Snell
<MS ACCESS MVP>

This is what happens when I exit the status field.
When
it says closed and I tab out of the field I get a
number
that pops up in it. I want it to look at the status
field
and if it sees anything but the word closed to
then
use
the datediff formula. If the word closed shows
up
in
the
status field then I want it to leave the Time
left
to
close field empty.


-----Original Message-----
I am not understanding what you want to do that is
different from what you
have posted as your code? Can you elaborate, please?

--
Ken Snell
<MS ACCESS MVP>

I have 3 fields one of which is called Status, one
called
Approved ECD and another called Time left to
close.
I
need to find out how to get the time left to close
field
to place a number of days left till the date
in
the
approved ECD field IF the status field does
not
say
closed. If it does say closed I would like
the
time
left
to close field to become empty or null. Below is
what I
have:

Public Sub Status_Exit(Cancel As Integer)
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d",
Now
(),
[Approved ECD])
End If
End Sub


Any help would be greatly appreciated.
 
Yes. Zip up a small sample of the database and email it, along with detailed
instructions about how the form is supposed to be used/work, to my email
address (obtain it by removing this is not real from the address).

I'll take a look at it as time permits.

--
Ken Snell
<MS ACCESS MVP>

marc said:
Is there anyway I can maybe send you a copy of what I have
so you can look at it?
-----Original Message-----
How can the value of "Approved ECD" field change? Does it change when a user
changes it? When you open the form on a new day (different "current date")?
Does some other event change it? You need to determine what is happening
when it "changes" if you want to "capture" that change so that you can do
something in the other controls.

Otherwise, you need to recalculate the values of Total_Behind_Schedule and
Time_Left_to_Close_Date controls whenever you open the form or change to a
different record. Then you don't need to "capture" the change of Approved
ECD. Can you identify an expression that would result in the correct
calculation each time? Then you could use that expression as the control
source for the controls.

I am having difficulty visualizing your form and table setup -- that is
hampering my ability to "see" a possible solution. I hope you're not trying
to store the values of Total_Behind_Schedule and Time_Left_to_Close_Date
controls in a table -- if they can be calculated, then you should calculate
them when you want to see them. Then my suggestion of using an expression as
the control source for these two controls makes even better sense.

As for having them show up only if positive, your expression could utilize a
statement similar to this; for example,
IIf([Status] <> "Closed", IIf(DateDiff("d", Now (), [Approved ECD]) >
0, DateDiff("d", Now(), [Approved ECD]), Null), Null)


--
Ken Snell
<MS ACCESS MVP>

marc said:
Ken,
Let me tell you what I am trying to do. I have a
database in which I am tracking some taskings with. I
would like to show either how many days left till the
close of the particular task or how many days past the ECD
(estimated close date). This is where the time left to
close and the behind schedule fields come in. What I
would like to be able to do is have the above 2 fields
update automatically when and if the approved ECD field
changes. Since I placed the code under the AfterUpdate I
don't think it will up date unless the Status field is
touched. Is there an easy way of doing this?

I would also like to have the time left to close and
behind schedule fields to only show up they are positive
numbers. for example if the time left to close date shows
a positive number and the behind schedule date shows a
negative number then the behind schedule field will be
null. Is this possible to do as well?



-----Original Message-----
Assuming that you're describing a control that is
displaying the value of
the "total behind schedule" field, you can use a line of
code similar to
what you used in your original code when the Status
control was "Closed":

Me.Total_Behind_Schedule = Null

Here would be the modified code:

Public Sub Status_AfterUpdate()
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now(),
[Approved ECD])
Me.Total_Behind_Schedule = Null
End If
End Sub

--
Ken Snell
<MS ACCESS MVP>



Ken,
Something has come along the same line as this one. If
you can help that would be great. I got the code to
work
for what I needed. Now i get a number in the time left
to
close field and the total behind schedule field. Lets
say
26 is the number. Time left to close say 26 and the
total
behind schedule says -26. I want to put some code into
the database that tells it to null the field that is
negative.



Also,
When the Approved ECD fields date changes I would like
to see the numbers in the fields mentioned above to
change. How can I do this?




-----Original Message-----
Ken,
Thanks for the help. I don't know why but the code
would not work for the on exit but works just fine for
the
after update. I thought the code should work that is
where I was getting confused. Again thanks for the
help.

-----Original Message-----
But that is what I understand that your code is doing.
Is
it not working?

If not, try moving it to the AfterUpdate event of the
Status field.

Sorry, but I am not understanding completely, I think.
--
Ken Snell
<MS ACCESS MVP>

This is what happens when I exit the status field.
When
it says closed and I tab out of the field I get a
number
that pops up in it. I want it to look at the status
field
and if it sees anything but the word closed to then
use
the datediff formula. If the word closed shows up
in
the
status field then I want it to leave the Time left
to
close field empty.


-----Original Message-----
I am not understanding what you want to do that is
different from what you
have posted as your code? Can you elaborate,
please?

--
Ken Snell
<MS ACCESS MVP>

I have 3 fields one of which is called Status,
one
called
Approved ECD and another called Time left to
close.
I
need to find out how to get the time left to
close
field
to place a number of days left till the date in
the
approved ECD field IF the status field does not
say
closed. If it does say closed I would like the
time
left
to close field to become empty or null. Below is
what I
have:

Public Sub Status_Exit(Cancel As Integer)
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d",
Now
(),
[Approved ECD])
End If
End Sub


Any help would be greatly appreciated.
 
I am not familiar with the Alison Balter book. I use ACCESS 2002 Bible,
ACCESS 2002 Developer's Handbook, Database Design for Mere Mortals,
Beginning ACCESS 2002 VBA, and ACCESS 2002 VBA Handbook for references. The
first three have lots of info on how to set up and normalize a database.
There are many other books out there as well: Running Microsoft ACCESS 2002
for another example.

My recommendation would be for you to get one of the first three books (or
any other that you find in a bookstore) and see how tables are designed, how
you use forms to interact with the tables, etc. There are numerous ways to
set up and use a database, and the time invested up front (though it seems
to be taking you away from doing the work) will greatly pay off as you
design the database and find that you can more easily do the things that you
want to do.

As I mentioned, ACCESS requires a steep learning curve, but it's well worth
the time because of its power and capabilities.

The basics are so broad that this newsgroup forum is not suited to giving
such overviews. However, as you begin to try out the examples and apply them
to your database, then post here with questions about the specific things
you're trying to do. Readers here are very willing to share knowledge and
help others learn what they've learned -- and the readers learn something
new as well!
 
Marc -

The second database that you sent does have the forms in it. I've opened the
main form, which appears to be the one of interest in our exchange. But I
must admit that its complexity makes it impossible for me to fully
understand how all fits together.

I did find the "Approved ECD" control and note that you currently don't have
any code on its AfterUpdate form. However, even without this code, because
the form's recordsource query contains a calculated field, to which the Time
Left to Close Date control is bound, any change made to the Approved ECD
value automatically causes the Time Left to Close Date control's value to
update. But I'm guessing that you want to store this value from Time Left to
Close Date control into the table -- and of course you cannot do that with
this query, because the field to which it's bound is a calculated field.

To store this value into the desired field in the underlying table, you must
bind this control to that field, not to the calculated field, in the form's
recordsource query. Then, use code on the AfterUpdate event of the Approved
ECD control to put the correct, updated value into that control (this is
what we were discussing earlier, I believe):

Private Sub [Approved ECD]_AfterUpdate()
If [AIStatus] <> "Closed" Then
If DateDiff("d",Now(),[Approved ECD]) > 0 Then
Me.[Time Left To Close Date].Value =
DateDiff("d",Now(),[Approved ECD])
Else
Me.[Time Left To Close Date].Value = Null
End If
Else
Me.[Time Left To Close Date].Value = Null
End If
' Don't show a value if the "time left" is negative
If Me.[Time Left To Close Date].Value < 0 Then Me.[Time Left To Close
Date].Value = Null
End Sub

But, storing this calculated value into the table seems to be inappropriate,
as you can recalculate it at any time when you need it; storing it wastes
database space and means that you must always update that field whenever the
"independent" values (those on which it's value depends) are changed.
Forgetting to update this value when the other data change means that your
data will be out of synchronization.

My review of the query that is the form's recordsource strongly suggests
that, as we've exchanged, your database's table design is very
unnormalized -- I am basing this conclusion on the use of "repetitive"
fields in the query where the only difference is the "number" that is in the
name of the field (e.g., Status_Weekly_17100 and Document Number1), but
because I do not know the structure and intent of the database, my
conclusion may be incorrect.

It seems that a significant amount of work has been exerted to set up this
database; however, at the risk of seeming "annoying", I strongly recommend
that it be redesigned so that it will be a better functioning database and
be one that is easier to maintain. As I mentioned, reading through some
ACCESS books will give you a better flavor for how tables should be
designed, how queries should be set up, etc. I am sorry that I cannot be
more specific on what must be done, but that would move beyond volunteering
(free) into consulting (paid).

Notwithstanding my recommendation re: redesign, it's likely that the desired
updates can be achieved in this database in its current setup, using the
information that I've given above (regarding which fields to bind to the
controls) and the earlier code snippets that would be used on the
AfterUpdate (and other) events for controls.
--
Ken Snell
<MS ACCESS MVP>


marc said:
Ken,
So what do you suggest for me to do. I am new to
this. I am taking over for someone and never had a chance
to learn properly. Does this book your talking about help
you with the basics. I have a book now and it is
called "Alison Balter's Mastering Access 2002 Desktop
Development". I want to learn the best way to do things
and I think the person who was doing the databases before
me learned on his own and I don't think he learned the
best way of doing things.
-----Original Message-----
Marc -

I have opened your database, and find no forms in it. I was understanding
that you were using a form for the data changes that you've posted about. I
need to see the forms that you're trying to use so that I might see better
what you've set up and why it may not be working.

A quick glance at your tblECD table (which I assume is the one of interest,
based on our previous exchanges) suggests that this table is not normalized
for database work and that you're trying to store information in differrent
fields based on calculations that you perform on different days. This is not
how to set up your database in an easily maintainable manner. Essentially,
your data in the tables is time-sensitive, and are "obsolete"/"out of date"
unless you constantly run updating queries to move things around.

The intent of the fields in your tblECD table appear to be better met by
using a query that takes the raw data and displays it in accordance with
your "business" rules concerning how many days are left, what the overdue
status is, etc.

I am not able to go through the database and make additional
recommendations, as I don't know the details about what you're wanting to
accomplish, which also would be needed in order to give detailed
recommendations.

You can obtain some good examples for setting up your tables and how to
display and use the data from a book on ACCESS. ACCESS "mastery" is a steep
learning curve, but as you climb that hill you'll be rewarded by a database
that is easy to use and easy to maintain.

If I'm missing the boat here, let me know. Please do post back with
questions or additional information.

--
Ken Snell
<MS ACCESS MVP>

Yes. Zip up a small sample of the database and email
it, along with
detailed
instructions about how the form is supposed to be used/work, to my email
address (obtain it by removing this is not real from the address).

I'll take a look at it as time permits.

--
Ken Snell
<MS ACCESS MVP>

Is there anyway I can maybe send you a copy of what I have
so you can look at it?

-----Original Message-----
How can the value of "Approved ECD" field change? Does it
change when a user
changes it? When you open the form on a new day
(different "current date")?
Does some other event change it? You need to determine
what is happening
when it "changes" if you want to "capture" that change so
that you can do
something in the other controls.

Otherwise, you need to recalculate the values of
Total_Behind_Schedule and
Time_Left_to_Close_Date controls whenever you open the
form or change to a
different record. Then you don't need to "capture" the
change of Approved
ECD. Can you identify an expression that would result in
the correct
calculation each time? Then you could use that expression
as the control
source for the controls.

I am having difficulty visualizing your form and table
setup -- that is
hampering my ability to "see" a possible solution. I hope
you're not trying
to store the values of Total_Behind_Schedule and
Time_Left_to_Close_Date
controls in a table -- if they can be calculated, then
you should calculate
them when you want to see them. Then my suggestion of
using an expression as
the control source for these two controls makes even
better sense.

As for having them show up only if positive, your
expression could utilize a
statement similar to this; for example,
IIf([Status] <> "Closed", IIf(DateDiff("d", Now
(), [Approved ECD]) >
0, DateDiff("d", Now(), [Approved ECD]), Null), Null)


--
Ken Snell
<MS ACCESS MVP>

Ken,
Let me tell you what I am trying to do. I have a
database in which I am tracking some taskings with. I
would like to show either how many days left till the
close of the particular task or how many days past the
ECD
(estimated close date). This is where the time left to
close and the behind schedule fields come in. What I
would like to be able to do is have the above 2 fields
update automatically when and if the approved ECD field
changes. Since I placed the code under the AfterUpdate
I
don't think it will up date unless the Status field is
touched. Is there an easy way of doing this?

I would also like to have the time left to close and
behind schedule fields to only show up they are positive
numbers. for example if the time left to close date
shows
a positive number and the behind schedule date shows a
negative number then the behind schedule field will be
null. Is this possible to do as well?



-----Original Message-----
Assuming that you're describing a control that is
displaying the value of
the "total behind schedule" field, you can use a line
of
code similar to
what you used in your original code when the Status
control was "Closed":

Me.Total_Behind_Schedule = Null

Here would be the modified code:

Public Sub Status_AfterUpdate()
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff("d", Now (),
[Approved ECD])
Me.Total_Behind_Schedule = Null
End If
End Sub

--
Ken Snell
<MS ACCESS MVP>



Ken,
Something has come along the same line as this one.
If
you can help that would be great. I got the code to
work
for what I needed. Now i get a number in the time
left
to
close field and the total behind schedule field.
Lets
say
26 is the number. Time left to close say 26 and the
total
behind schedule says -26. I want to put some code
into
the database that tells it to null the field that is
negative.



Also,
When the Approved ECD fields date changes I would
like
to see the numbers in the fields mentioned above to
change. How can I do this?




-----Original Message-----
Ken,
Thanks for the help. I don't know why but the
code
would not work for the on exit but works just fine
for
the
after update. I thought the code should work that
is
where I was getting confused. Again thanks for the
help.

-----Original Message-----
But that is what I understand that your code is
doing.
Is
it not working?

If not, try moving it to the AfterUpdate event of
the
Status field.

Sorry, but I am not understanding completely, I
think.
--
Ken Snell
<MS ACCESS MVP>

This is what happens when I exit the status
field.
When
it says closed and I tab out of the field I get a
number
that pops up in it. I want it to look at the
status
field
and if it sees anything but the word closed to
then
use
the datediff formula. If the word closed shows
up
in
the
status field then I want it to leave the Time
left
to
close field empty.


-----Original Message-----
I am not understanding what you want to do that
is
different from what you
have posted as your code? Can you elaborate,
please?

--
Ken Snell
<MS ACCESS MVP>

[email protected]...
I have 3 fields one of which is called Status,
one
called
Approved ECD and another called Time left to
close.
I
need to find out how to get the time left to
close
field
to place a number of days left till the date
in
the
approved ECD field IF the status field does
not
say
closed. If it does say closed I would like
the
time
left
to close field to become empty or null.
Below is
what I
have:

Public Sub Status_Exit(Cancel As Integer)
If Me.Status = "Closed" Then
Me.Time_Left_to_Close_Date = Null
Else
Me.Time_Left_to_Close_Date = DateDiff ("d",
Now
(),
[Approved ECD])
End If
End Sub


Any help would be greatly appreciated.


.
 
Ken,
Thanks for all of your help. I will try and normalize
the tables better. The book I have here dosen't go into
normalization very well. I am in the process of getting a
couple more books and we'll see what happens.
 
Back
Top