Unload Event Problem

P

Pam

Hi,

I'm trying to get users to fill in stop time on a time tracking database
before closing database. I have a hidden form that is used as a popup when
they forget they have start time entered on one job and try to start time on
another job. I'm using the UnloadEvent on this same form to pop up when
they close out of the database. It works well for one record if I fill in
the stop time, but it allows me to close when there are other records with
stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before exiting db, I
would appreciate hearing them.
Thanks,
Pam
 
A

Allen Browne

Use the BeforeUpdate event procedure of the form (not text box), rather than
the form's Unload event.

UnLoad is too late: by that stage the bad record has already been saved.
 
P

Pam

Allen,

Thanks for replying. I used the same code that I listed in my first message
and applied it to the BeforeUpdate event procedure and tested with two open
"StopTime" entries and closed the db. It didn't catch that these two
entries were not complete before closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Allen Browne said:
Use the BeforeUpdate event procedure of the form (not text box), rather
than the form's Unload event.

UnLoad is too late: by that stage the bad record has already been saved.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
Hi,

I'm trying to get users to fill in stop time on a time tracking database
before closing database. I have a hidden form that is used as a popup
when they forget they have start time entered on one job and try to start
time on another job. I'm using the UnloadEvent on this same form to pop
up when they close out of the database. It works well for one record if
I fill in the stop time, but it allows me to close when there are other
records with stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before exiting db, I
would appreciate hearing them.
Thanks,
Pam
 
A

Allen Browne

I presume that prevented the bad records being saved to the table, but it
failed to report this to you.

That's a long-standing bug in Access. For details, see:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The solution is to add code to the command button that closes the form to
explicitly save the record before you close the form. That generates a
trappable error, and so you are notified that the record was not saved.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
Allen,

Thanks for replying. I used the same code that I listed in my first
message and applied it to the BeforeUpdate event procedure and tested with
two open "StopTime" entries and closed the db. It didn't catch that these
two entries were not complete before closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Allen Browne said:
Use the BeforeUpdate event procedure of the form (not text box), rather
than the form's Unload event.

UnLoad is too late: by that stage the bad record has already been saved.

Pam said:
Hi,

I'm trying to get users to fill in stop time on a time tracking database
before closing database. I have a hidden form that is used as a popup
when they forget they have start time entered on one job and try to
start time on another job. I'm using the UnloadEvent on this same form
to pop up when they close out of the database. It works well for one
record if I fill in the stop time, but it allows me to close when there
are other records with stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before exiting db,
I would appreciate hearing them.
 
P

Pam

Allen,

Your last comment stated "so you are notified that the record was not
saved". I don't want the user to see a message that the record was not
saved with an "ok" button to press. These users will press okay and go on
about their business. I want them to be required to put time in the
"StopTime" field for any jobs left running before quitting the database.

Far be it from me to question your suggestions (most of this is Greek to me
anyway), but will you please explain the posts I've read about using a
hidden form with the Unload event for anything that has to do with
procedures before closing a database. I really thought I was headed in the
right direction.

I appreciate your help and time.
Pam


Allen Browne said:
I presume that prevented the bad records being saved to the table, but it
failed to report this to you.

That's a long-standing bug in Access. For details, see:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The solution is to add code to the command button that closes the form to
explicitly save the record before you close the form. That generates a
trappable error, and so you are notified that the record was not saved.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
Allen,

Thanks for replying. I used the same code that I listed in my first
message and applied it to the BeforeUpdate event procedure and tested
with two open "StopTime" entries and closed the db. It didn't catch that
these two entries were not complete before closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Allen Browne said:
Use the BeforeUpdate event procedure of the form (not text box), rather
than the form's Unload event.

UnLoad is too late: by that stage the bad record has already been saved.

Hi,

I'm trying to get users to fill in stop time on a time tracking
database before closing database. I have a hidden form that is used as
a popup when they forget they have start time entered on one job and
try to start time on another job. I'm using the UnloadEvent on this
same form to pop up when they close out of the database. It works well
for one record if I fill in the stop time, but it allows me to close
when there are other records with stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before exiting db,
I would appreciate hearing them.
 
A

Allen Browne

Okay, I'm a bit confused here.

Reading back through your thread, it seems you have 2 forms:
- a form where users enter jobs
- a hidden form where you are trying to prevent them closing the database if
the job lacks a close time.

So you already have the jobs entered and saved without a close time, and you
are now trying to insist that the database cannot be closed unless the user
goes back and adds a close time to those jobs?

If that's the idea, your hidden form would do something like this:

Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(DLookup("ID", "JobTable", "[StopTime] Is Null")) Then
Cancel = True
MsgBox "You must enter a Stop Time in all records before you can
close the database."
Docmd.OpenForm "frmJob",, "[StopTime] Is Null", _
WindowMode:=acDialog
End If
End Sub

This kind of thing bothers me: I think there is a temptation to just crash
out of Access or turn the computer off rather than enter all the required
data. As you probably know that's a good way to corrupt the database. An
alternative approach might be to exeute an Update query that sets the
StopTime to Now() for all records where it is null.

If this is a multi-user database, there is also the question of how you
identify the correct records that each user must fill in before they can
close.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
Allen,

Your last comment stated "so you are notified that the record was not
saved". I don't want the user to see a message that the record was not
saved with an "ok" button to press. These users will press okay and go on
about their business. I want them to be required to put time in the
"StopTime" field for any jobs left running before quitting the database.

Far be it from me to question your suggestions (most of this is Greek to
me anyway), but will you please explain the posts I've read about using a
hidden form with the Unload event for anything that has to do with
procedures before closing a database. I really thought I was headed in the
right direction.

I appreciate your help and time.
Pam


Allen Browne said:
I presume that prevented the bad records being saved to the table, but it
failed to report this to you.

That's a long-standing bug in Access. For details, see:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The solution is to add code to the command button that closes the form to
explicitly save the record before you close the form. That generates a
trappable error, and so you are notified that the record was not saved.

Pam said:
Allen,

Thanks for replying. I used the same code that I listed in my first
message and applied it to the BeforeUpdate event procedure and tested
with two open "StopTime" entries and closed the db. It didn't catch
that these two entries were not complete before closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Use the BeforeUpdate event procedure of the form (not text box), rather
than the form's Unload event.

UnLoad is too late: by that stage the bad record has already been
saved.

Hi,

I'm trying to get users to fill in stop time on a time tracking
database before closing database. I have a hidden form that is used
as a popup when they forget they have start time entered on one job
and try to start time on another job. I'm using the UnloadEvent on
this same form to pop up when they close out of the database. It
works well for one record if I fill in the stop time, but it allows me
to close when there are other records with stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before exiting
db, I would appreciate hearing them.
 
P

Pam

Allen,

I'm sorry for the confusion. Based on your statements below, I'll try to
clarify.

I do have two forms.
- a form where users enter jobs
Yes, they enter name, start time, and type of work performed for selected
job number.
- a hidden form where you are trying to prevent them closing the database
if the job lacks a close time.
Yes, it is hidden and is used so that when they start another job it will
popup reminding them they are still logged on with start time entered and
stop time empty. I wanted to use this same form when they close the
database.
So you already have the jobs entered and saved without a close time,
Yes, the user logs onto a specific job, clicks all necessary info including
start time and logs off to start work on shop floor. When user completes
task, he is supposed to come back to computer and select his name and job
number and it will open form to enter stop time.
But this is where the problem is, some will leave for the day without
logging off the computer and time continually runs until the next time they
log on. They click stop time, which is set to Now() with double click, and
never bother to tell anyone until it shows up on some report a month later.
An alternative approach might be to exeute an Update query that sets the
StopTime to Now() for all records where it is null.
I had originally thought about this, searched thru posts and came up with
the Unload event for hidden forms and since I already had one in place for
catching between jobs why not use it for when the computer is shut down.

Can you tell me how to set up the Update query (I've only rarely used them)
to set StopTime to Now() upon closing? I like this idea better anyway.

If this is a multi-user database, there is also the question of how you
identify the correct records that each user must fill in before they can
close.
I don't care if whoever shuts down the computer in the evening is the one to
log off another user's time, as long as it doesn't run for days (like thru
the weekend).

Thanks again for your help,
Pam


Allen Browne said:
Okay, I'm a bit confused here.

Reading back through your thread, it seems you have 2 forms:
- a form where users enter jobs
- a hidden form where you are trying to prevent them closing the database
if the job lacks a close time.

So you already have the jobs entered and saved without a close time, and
you are now trying to insist that the database cannot be closed unless the
user goes back and adds a close time to those jobs?

If that's the idea, your hidden form would do something like this:

Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(DLookup("ID", "JobTable", "[StopTime] Is Null")) Then
Cancel = True
MsgBox "You must enter a Stop Time in all records before you can
close the database."
Docmd.OpenForm "frmJob",, "[StopTime] Is Null", _
WindowMode:=acDialog
End If
End Sub

This kind of thing bothers me: I think there is a temptation to just crash
out of Access or turn the computer off rather than enter all the required
data. As you probably know that's a good way to corrupt the database. An
alternative approach might be to exeute an Update query that sets the
StopTime to Now() for all records where it is null.

If this is a multi-user database, there is also the question of how you
identify the correct records that each user must fill in before they can
close.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
Allen,

Your last comment stated "so you are notified that the record was not
saved". I don't want the user to see a message that the record was not
saved with an "ok" button to press. These users will press okay and go
on about their business. I want them to be required to put time in the
"StopTime" field for any jobs left running before quitting the database.

Far be it from me to question your suggestions (most of this is Greek to
me anyway), but will you please explain the posts I've read about using a
hidden form with the Unload event for anything that has to do with
procedures before closing a database. I really thought I was headed in
the right direction.

I appreciate your help and time.
Pam


Allen Browne said:
I presume that prevented the bad records being saved to the table, but it
failed to report this to you.

That's a long-standing bug in Access. For details, see:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The solution is to add code to the command button that closes the form
to explicitly save the record before you close the form. That generates
a trappable error, and so you are notified that the record was not
saved.

Allen,

Thanks for replying. I used the same code that I listed in my first
message and applied it to the BeforeUpdate event procedure and tested
with two open "StopTime" entries and closed the db. It didn't catch
that these two entries were not complete before closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Use the BeforeUpdate event procedure of the form (not text box),
rather than the form's Unload event.

UnLoad is too late: by that stage the bad record has already been
saved.

Hi,

I'm trying to get users to fill in stop time on a time tracking
database before closing database. I have a hidden form that is used
as a popup when they forget they have start time entered on one job
and try to start time on another job. I'm using the UnloadEvent on
this same form to pop up when they close out of the database. It
works well for one record if I fill in the stop time, but it allows
me to close when there are other records with stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before exiting
db, I would appreciate hearing them.
 
A

Allen Browne

The update query is dead easy:
strSql = "UPDATE Table1 SET StopTime = Now() WHERE StopTime Is Null;"
dbEngine(0)(0).Execute strSql, dbFailOnError

You probably want to close the form first (so as not to get concurrency
problems.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
Allen,

I'm sorry for the confusion. Based on your statements below, I'll try to
clarify.

I do have two forms.
- a form where users enter jobs
Yes, they enter name, start time, and type of work performed for selected
job number.
- a hidden form where you are trying to prevent them closing the database
if the job lacks a close time.
Yes, it is hidden and is used so that when they start another job it will
popup reminding them they are still logged on with start time entered and
stop time empty. I wanted to use this same form when they close the
database.
So you already have the jobs entered and saved without a close time,
Yes, the user logs onto a specific job, clicks all necessary info
including start time and logs off to start work on shop floor. When user
completes task, he is supposed to come back to computer and select his
name and job number and it will open form to enter stop time.
But this is where the problem is, some will leave for the day without
logging off the computer and time continually runs until the next time
they log on. They click stop time, which is set to Now() with double
click, and never bother to tell anyone until it shows up on some report a
month later.
An alternative approach might be to exeute an Update query that sets the
StopTime to Now() for all records where it is null.
I had originally thought about this, searched thru posts and came up with
the Unload event for hidden forms and since I already had one in place for
catching between jobs why not use it for when the computer is shut down.

Can you tell me how to set up the Update query (I've only rarely used
them) to set StopTime to Now() upon closing? I like this idea better
anyway.

If this is a multi-user database, there is also the question of how you
identify the correct records that each user must fill in before they can
close.
I don't care if whoever shuts down the computer in the evening is the one
to log off another user's time, as long as it doesn't run for days (like
thru the weekend).

Thanks again for your help,
Pam


Allen Browne said:
Okay, I'm a bit confused here.

Reading back through your thread, it seems you have 2 forms:
- a form where users enter jobs
- a hidden form where you are trying to prevent them closing the database
if the job lacks a close time.

So you already have the jobs entered and saved without a close time, and
you are now trying to insist that the database cannot be closed unless
the user goes back and adds a close time to those jobs?

If that's the idea, your hidden form would do something like this:

Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(DLookup("ID", "JobTable", "[StopTime] Is Null")) Then
Cancel = True
MsgBox "You must enter a Stop Time in all records before you can
close the database."
Docmd.OpenForm "frmJob",, "[StopTime] Is Null", _
WindowMode:=acDialog
End If
End Sub

This kind of thing bothers me: I think there is a temptation to just
crash out of Access or turn the computer off rather than enter all the
required data. As you probably know that's a good way to corrupt the
database. An alternative approach might be to exeute an Update query that
sets the StopTime to Now() for all records where it is null.

If this is a multi-user database, there is also the question of how you
identify the correct records that each user must fill in before they can
close.

Pam said:
Allen,

Your last comment stated "so you are notified that the record was not
saved". I don't want the user to see a message that the record was not
saved with an "ok" button to press. These users will press okay and go
on about their business. I want them to be required to put time in the
"StopTime" field for any jobs left running before quitting the database.

Far be it from me to question your suggestions (most of this is Greek to
me anyway), but will you please explain the posts I've read about using
a hidden form with the Unload event for anything that has to do with
procedures before closing a database. I really thought I was headed in
the right direction.

I appreciate your help and time.
Pam


I presume that prevented the bad records being saved to the table, but
it failed to report this to you.

That's a long-standing bug in Access. For details, see:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The solution is to add code to the command button that closes the form
to explicitly save the record before you close the form. That generates
a trappable error, and so you are notified that the record was not
saved.

Allen,

Thanks for replying. I used the same code that I listed in my first
message and applied it to the BeforeUpdate event procedure and tested
with two open "StopTime" entries and closed the db. It didn't catch
that these two entries were not complete before closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Use the BeforeUpdate event procedure of the form (not text box),
rather than the form's Unload event.

UnLoad is too late: by that stage the bad record has already been
saved.

Hi,

I'm trying to get users to fill in stop time on a time tracking
database before closing database. I have a hidden form that is used
as a popup when they forget they have start time entered on one job
and try to start time on another job. I'm using the UnloadEvent on
this same form to pop up when they close out of the database. It
works well for one record if I fill in the stop time, but it allows
me to close when there are other records with stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before exiting
db, I would appreciate hearing them.
 
P

Pam

I'm sorry for being slow. Where would I put this code if I close the hidden
form first?



Allen Browne said:
The update query is dead easy:
strSql = "UPDATE Table1 SET StopTime = Now() WHERE StopTime Is Null;"
dbEngine(0)(0).Execute strSql, dbFailOnError

You probably want to close the form first (so as not to get concurrency
problems.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
Allen,

I'm sorry for the confusion. Based on your statements below, I'll try to
clarify.

I do have two forms.
- a form where users enter jobs
Yes, they enter name, start time, and type of work performed for selected
job number.
- a hidden form where you are trying to prevent them closing the
database if the job lacks a close time.
Yes, it is hidden and is used so that when they start another job it will
popup reminding them they are still logged on with start time entered and
stop time empty. I wanted to use this same form when they close the
database.
So you already have the jobs entered and saved without a close time,
Yes, the user logs onto a specific job, clicks all necessary info
including start time and logs off to start work on shop floor. When user
completes task, he is supposed to come back to computer and select his
name and job number and it will open form to enter stop time.
But this is where the problem is, some will leave for the day without
logging off the computer and time continually runs until the next time
they log on. They click stop time, which is set to Now() with double
click, and never bother to tell anyone until it shows up on some report a
month later.
An alternative approach might be to exeute an Update query that sets the
StopTime to Now() for all records where it is null.
I had originally thought about this, searched thru posts and came up with
the Unload event for hidden forms and since I already had one in place
for catching between jobs why not use it for when the computer is shut
down.

Can you tell me how to set up the Update query (I've only rarely used
them) to set StopTime to Now() upon closing? I like this idea better
anyway.

If this is a multi-user database, there is also the question of how you
identify the correct records that each user must fill in before they can
close.
I don't care if whoever shuts down the computer in the evening is the one
to log off another user's time, as long as it doesn't run for days (like
thru the weekend).

Thanks again for your help,
Pam


Allen Browne said:
Okay, I'm a bit confused here.

Reading back through your thread, it seems you have 2 forms:
- a form where users enter jobs
- a hidden form where you are trying to prevent them closing the
database if the job lacks a close time.

So you already have the jobs entered and saved without a close time, and
you are now trying to insist that the database cannot be closed unless
the user goes back and adds a close time to those jobs?

If that's the idea, your hidden form would do something like this:

Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(DLookup("ID", "JobTable", "[StopTime] Is Null")) Then
Cancel = True
MsgBox "You must enter a Stop Time in all records before you can
close the database."
Docmd.OpenForm "frmJob",, "[StopTime] Is Null", _
WindowMode:=acDialog
End If
End Sub

This kind of thing bothers me: I think there is a temptation to just
crash out of Access or turn the computer off rather than enter all the
required data. As you probably know that's a good way to corrupt the
database. An alternative approach might be to exeute an Update query
that sets the StopTime to Now() for all records where it is null.

If this is a multi-user database, there is also the question of how you
identify the correct records that each user must fill in before they can
close.

Allen,

Your last comment stated "so you are notified that the record was not
saved". I don't want the user to see a message that the record was not
saved with an "ok" button to press. These users will press okay and go
on about their business. I want them to be required to put time in the
"StopTime" field for any jobs left running before quitting the
database.

Far be it from me to question your suggestions (most of this is Greek
to me anyway), but will you please explain the posts I've read about
using a hidden form with the Unload event for anything that has to do
with procedures before closing a database. I really thought I was
headed in the right direction.

I appreciate your help and time.
Pam


I presume that prevented the bad records being saved to the table, but
it failed to report this to you.

That's a long-standing bug in Access. For details, see:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The solution is to add code to the command button that closes the form
to explicitly save the record before you close the form. That
generates a trappable error, and so you are notified that the record
was not saved.

Allen,

Thanks for replying. I used the same code that I listed in my first
message and applied it to the BeforeUpdate event procedure and tested
with two open "StopTime" entries and closed the db. It didn't catch
that these two entries were not complete before closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Use the BeforeUpdate event procedure of the form (not text box),
rather than the form's Unload event.

UnLoad is too late: by that stage the bad record has already been
saved.

Hi,

I'm trying to get users to fill in stop time on a time tracking
database before closing database. I have a hidden form that is
used as a popup when they forget they have start time entered on
one job and try to start time on another job. I'm using the
UnloadEvent on this same form to pop up when they close out of the
database. It works well for one record if I fill in the stop time,
but it allows me to close when there are other records with stop
time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before exiting
db, I would appreciate hearing them.
 
A

Allen Browne

Sorry, Pam: the idea is to close the bound form first, since it could be
dirty with a record that needs to be saved in the same table.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
I'm sorry for being slow. Where would I put this code if I close the
hidden form first?



Allen Browne said:
The update query is dead easy:
strSql = "UPDATE Table1 SET StopTime = Now() WHERE StopTime Is Null;"
dbEngine(0)(0).Execute strSql, dbFailOnError

You probably want to close the form first (so as not to get concurrency
problems.)

Pam said:
Allen,

I'm sorry for the confusion. Based on your statements below, I'll try
to clarify.

I do have two forms.
- a form where users enter jobs
Yes, they enter name, start time, and type of work performed for
selected job number.
- a hidden form where you are trying to prevent them closing the
database if the job lacks a close time.
Yes, it is hidden and is used so that when they start another job it
will popup reminding them they are still logged on with start time
entered and stop time empty. I wanted to use this same form when they
close the database.
So you already have the jobs entered and saved without a close time,
Yes, the user logs onto a specific job, clicks all necessary info
including start time and logs off to start work on shop floor. When
user completes task, he is supposed to come back to computer and select
his name and job number and it will open form to enter stop time.
But this is where the problem is, some will leave for the day without
logging off the computer and time continually runs until the next time
they log on. They click stop time, which is set to Now() with double
click, and never bother to tell anyone until it shows up on some report
a month later.

An alternative approach might be to exeute an Update query that sets
the StopTime to Now() for all records where it is null.
I had originally thought about this, searched thru posts and came up
with the Unload event for hidden forms and since I already had one in
place for catching between jobs why not use it for when the computer is
shut down.

Can you tell me how to set up the Update query (I've only rarely used
them) to set StopTime to Now() upon closing? I like this idea better
anyway.


If this is a multi-user database, there is also the question of how you
identify the correct records that each user must fill in before they
can close.
I don't care if whoever shuts down the computer in the evening is the
one to log off another user's time, as long as it doesn't run for days
(like thru the weekend).

Thanks again for your help,
Pam


Okay, I'm a bit confused here.

Reading back through your thread, it seems you have 2 forms:
- a form where users enter jobs
- a hidden form where you are trying to prevent them closing the
database if the job lacks a close time.

So you already have the jobs entered and saved without a close time,
and you are now trying to insist that the database cannot be closed
unless the user goes back and adds a close time to those jobs?

If that's the idea, your hidden form would do something like this:

Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(DLookup("ID", "JobTable", "[StopTime] Is Null")) Then
Cancel = True
MsgBox "You must enter a Stop Time in all records before you can
close the database."
Docmd.OpenForm "frmJob",, "[StopTime] Is Null", _
WindowMode:=acDialog
End If
End Sub

This kind of thing bothers me: I think there is a temptation to just
crash out of Access or turn the computer off rather than enter all the
required data. As you probably know that's a good way to corrupt the
database. An alternative approach might be to exeute an Update query
that sets the StopTime to Now() for all records where it is null.

If this is a multi-user database, there is also the question of how you
identify the correct records that each user must fill in before they
can close.

Allen,

Your last comment stated "so you are notified that the record was not
saved". I don't want the user to see a message that the record was
not saved with an "ok" button to press. These users will press okay
and go on about their business. I want them to be required to put
time in the "StopTime" field for any jobs left running before quitting
the database.

Far be it from me to question your suggestions (most of this is Greek
to me anyway), but will you please explain the posts I've read about
using a hidden form with the Unload event for anything that has to do
with procedures before closing a database. I really thought I was
headed in the right direction.

I appreciate your help and time.
Pam


I presume that prevented the bad records being saved to the table, but
it failed to report this to you.

That's a long-standing bug in Access. For details, see:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The solution is to add code to the command button that closes the
form to explicitly save the record before you close the form. That
generates a trappable error, and so you are notified that the record
was not saved.

Allen,

Thanks for replying. I used the same code that I listed in my first
message and applied it to the BeforeUpdate event procedure and
tested with two open "StopTime" entries and closed the db. It
didn't catch that these two entries were not complete before
closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Use the BeforeUpdate event procedure of the form (not text box),
rather than the form's Unload event.

UnLoad is too late: by that stage the bad record has already been
saved.

Hi,

I'm trying to get users to fill in stop time on a time tracking
database before closing database. I have a hidden form that is
used as a popup when they forget they have start time entered on
one job and try to start time on another job. I'm using the
UnloadEvent on this same form to pop up when they close out of the
database. It works well for one record if I fill in the stop
time, but it allows me to close when there are other records with
stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before
exiting db, I would appreciate hearing them.
 
P

Pam

Allen,

I'm sorry to be such a pest, but you've shown me flaws in both scenarios. I
did get both methods to work and then realized how this may not be the most
efficient solution to this problem.
The unload event on the hidden form with null StopTime forcing user to enter
stop time to exit db and StopTime automatically filled in when db is shut
down thru update query would be a problem if the db were shut down before
quitting time for any reason - all time would be stopped while work
continued.
I have two computers set up in two separate shops. I thought a form to pop
up listing all those still logged on. If a user knew someone had left, they
could stop their time then. I set a command button on switchboard to open
this form if StopTime was null, disable the "x" in the upper right corner,
but if users are still working I can't come up with a solution to close
(bypass) the popup and shut down one computer while the other is still on.
I'm open to any suggestions you may have. Once again, thank you for your
time and help.
Pam





Allen Browne said:
Sorry, Pam: the idea is to close the bound form first, since it could be
dirty with a record that needs to be saved in the same table.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
I'm sorry for being slow. Where would I put this code if I close the
hidden form first?



Allen Browne said:
The update query is dead easy:
strSql = "UPDATE Table1 SET StopTime = Now() WHERE StopTime Is Null;"
dbEngine(0)(0).Execute strSql, dbFailOnError

You probably want to close the form first (so as not to get concurrency
problems.)

Allen,

I'm sorry for the confusion. Based on your statements below, I'll try
to clarify.

I do have two forms.
- a form where users enter jobs
Yes, they enter name, start time, and type of work performed for
selected job number.
- a hidden form where you are trying to prevent them closing the
database if the job lacks a close time.
Yes, it is hidden and is used so that when they start another job it
will popup reminding them they are still logged on with start time
entered and stop time empty. I wanted to use this same form when they
close the database.
So you already have the jobs entered and saved without a close time,
Yes, the user logs onto a specific job, clicks all necessary info
including start time and logs off to start work on shop floor. When
user completes task, he is supposed to come back to computer and select
his name and job number and it will open form to enter stop time.
But this is where the problem is, some will leave for the day without
logging off the computer and time continually runs until the next time
they log on. They click stop time, which is set to Now() with double
click, and never bother to tell anyone until it shows up on some report
a month later.

An alternative approach might be to exeute an Update query that sets
the StopTime to Now() for all records where it is null.
I had originally thought about this, searched thru posts and came up
with the Unload event for hidden forms and since I already had one in
place for catching between jobs why not use it for when the computer is
shut down.

Can you tell me how to set up the Update query (I've only rarely used
them) to set StopTime to Now() upon closing? I like this idea better
anyway.


If this is a multi-user database, there is also the question of how
you identify the correct records that each user must fill in before
they can close.
I don't care if whoever shuts down the computer in the evening is the
one to log off another user's time, as long as it doesn't run for days
(like thru the weekend).

Thanks again for your help,
Pam


Okay, I'm a bit confused here.

Reading back through your thread, it seems you have 2 forms:
- a form where users enter jobs
- a hidden form where you are trying to prevent them closing the
database if the job lacks a close time.

So you already have the jobs entered and saved without a close time,
and you are now trying to insist that the database cannot be closed
unless the user goes back and adds a close time to those jobs?

If that's the idea, your hidden form would do something like this:

Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(DLookup("ID", "JobTable", "[StopTime] Is Null")) Then
Cancel = True
MsgBox "You must enter a Stop Time in all records before you
can close the database."
Docmd.OpenForm "frmJob",, "[StopTime] Is Null", _
WindowMode:=acDialog
End If
End Sub

This kind of thing bothers me: I think there is a temptation to just
crash out of Access or turn the computer off rather than enter all the
required data. As you probably know that's a good way to corrupt the
database. An alternative approach might be to exeute an Update query
that sets the StopTime to Now() for all records where it is null.

If this is a multi-user database, there is also the question of how
you identify the correct records that each user must fill in before
they can close.

Allen,

Your last comment stated "so you are notified that the record was not
saved". I don't want the user to see a message that the record was
not saved with an "ok" button to press. These users will press okay
and go on about their business. I want them to be required to put
time in the "StopTime" field for any jobs left running before
quitting the database.

Far be it from me to question your suggestions (most of this is Greek
to me anyway), but will you please explain the posts I've read about
using a hidden form with the Unload event for anything that has to do
with procedures before closing a database. I really thought I was
headed in the right direction.

I appreciate your help and time.
Pam


I presume that prevented the bad records being saved to the table,
but it failed to report this to you.

That's a long-standing bug in Access. For details, see:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The solution is to add code to the command button that closes the
form to explicitly save the record before you close the form. That
generates a trappable error, and so you are notified that the record
was not saved.

Allen,

Thanks for replying. I used the same code that I listed in my
first message and applied it to the BeforeUpdate event procedure
and tested with two open "StopTime" entries and closed the db. It
didn't catch that these two entries were not complete before
closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Use the BeforeUpdate event procedure of the form (not text box),
rather than the form's Unload event.

UnLoad is too late: by that stage the bad record has already been
saved.

Hi,

I'm trying to get users to fill in stop time on a time tracking
database before closing database. I have a hidden form that is
used as a popup when they forget they have start time entered on
one job and try to start time on another job. I'm using the
UnloadEvent on this same form to pop up when they close out of
the database. It works well for one record if I fill in the stop
time, but it allows me to close when there are other records with
stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before
exiting db, I would appreciate hearing them.
 
A

Allen Browne

Okay, this is opening up another whole can of worms, I think.

If you have multiple users in the same back end, and some are still working
so they validly have records with no StopTime yet, but you want to allow the
current user to close their instance of the database, but they must enter
their StopTime, you will have to track who created/is editing each of the
jobs and execute the Update query such that it updates only the jobs
relating to the user who is closing down.

As there's several steps of logic to implementing that, it's probably
getting beyond what we can do in a newsgroup posting.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
Allen,

I'm sorry to be such a pest, but you've shown me flaws in both scenarios.
I did get both methods to work and then realized how this may not be the
most efficient solution to this problem.
The unload event on the hidden form with null StopTime forcing user to
enter stop time to exit db and StopTime automatically filled in when db is
shut down thru update query would be a problem if the db were shut down
before quitting time for any reason - all time would be stopped while work
continued.
I have two computers set up in two separate shops. I thought a form to pop
up listing all those still logged on. If a user knew someone had left,
they could stop their time then. I set a command button on switchboard to
open this form if StopTime was null, disable the "x" in the upper right
corner, but if users are still working I can't come up with a solution to
close (bypass) the popup and shut down one computer while the other is
still on.
I'm open to any suggestions you may have. Once again, thank you for your
time and help.
Pam

Allen Browne said:
Sorry, Pam: the idea is to close the bound form first, since it could be
dirty with a record that needs to be saved in the same table.

Pam said:
I'm sorry for being slow. Where would I put this code if I close the
hidden form first?



The update query is dead easy:
strSql = "UPDATE Table1 SET StopTime = Now() WHERE StopTime Is
Null;"
dbEngine(0)(0).Execute strSql, dbFailOnError

You probably want to close the form first (so as not to get concurrency
problems.)

Allen,

I'm sorry for the confusion. Based on your statements below, I'll try
to clarify.

I do have two forms.
- a form where users enter jobs
Yes, they enter name, start time, and type of work performed for
selected job number.
- a hidden form where you are trying to prevent them closing the
database if the job lacks a close time.
Yes, it is hidden and is used so that when they start another job it
will popup reminding them they are still logged on with start time
entered and stop time empty. I wanted to use this same form when they
close the database.
So you already have the jobs entered and saved without a close time,
Yes, the user logs onto a specific job, clicks all necessary info
including start time and logs off to start work on shop floor. When
user completes task, he is supposed to come back to computer and
select his name and job number and it will open form to enter stop
time.
But this is where the problem is, some will leave for the day without
logging off the computer and time continually runs until the next time
they log on. They click stop time, which is set to Now() with double
click, and never bother to tell anyone until it shows up on some
report a month later.

An alternative approach might be to exeute an Update query that sets
the StopTime to Now() for all records where it is null.
I had originally thought about this, searched thru posts and came up
with the Unload event for hidden forms and since I already had one in
place for catching between jobs why not use it for when the computer
is shut down.

Can you tell me how to set up the Update query (I've only rarely used
them) to set StopTime to Now() upon closing? I like this idea better
anyway.


If this is a multi-user database, there is also the question of how
you identify the correct records that each user must fill in before
they can close.
I don't care if whoever shuts down the computer in the evening is the
one to log off another user's time, as long as it doesn't run for days
(like thru the weekend).

Thanks again for your help,
Pam


Okay, I'm a bit confused here.

Reading back through your thread, it seems you have 2 forms:
- a form where users enter jobs
- a hidden form where you are trying to prevent them closing the
database if the job lacks a close time.

So you already have the jobs entered and saved without a close time,
and you are now trying to insist that the database cannot be closed
unless the user goes back and adds a close time to those jobs?

If that's the idea, your hidden form would do something like this:

Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(DLookup("ID", "JobTable", "[StopTime] Is Null"))
Then
Cancel = True
MsgBox "You must enter a Stop Time in all records before you
can close the database."
Docmd.OpenForm "frmJob",, "[StopTime] Is Null", _
WindowMode:=acDialog
End If
End Sub

This kind of thing bothers me: I think there is a temptation to just
crash out of Access or turn the computer off rather than enter all
the required data. As you probably know that's a good way to corrupt
the database. An alternative approach might be to exeute an Update
query that sets the StopTime to Now() for all records where it is
null.

If this is a multi-user database, there is also the question of how
you identify the correct records that each user must fill in before
they can close.

Allen,

Your last comment stated "so you are notified that the record was
not saved". I don't want the user to see a message that the record
was not saved with an "ok" button to press. These users will press
okay and go on about their business. I want them to be required to
put time in the "StopTime" field for any jobs left running before
quitting the database.

Far be it from me to question your suggestions (most of this is
Greek to me anyway), but will you please explain the posts I've read
about using a hidden form with the Unload event for anything that
has to do with procedures before closing a database. I really
thought I was headed in the right direction.

I appreciate your help and time.
Pam


I presume that prevented the bad records being saved to the table,
but it failed to report this to you.

That's a long-standing bug in Access. For details, see:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The solution is to add code to the command button that closes the
form to explicitly save the record before you close the form. That
generates a trappable error, and so you are notified that the
record was not saved.

Allen,

Thanks for replying. I used the same code that I listed in my
first message and applied it to the BeforeUpdate event procedure
and tested with two open "StopTime" entries and closed the db. It
didn't catch that these two entries were not complete before
closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Use the BeforeUpdate event procedure of the form (not text box),
rather than the form's Unload event.

UnLoad is too late: by that stage the bad record has already been
saved.

Hi,

I'm trying to get users to fill in stop time on a time tracking
database before closing database. I have a hidden form that is
used as a popup when they forget they have start time entered on
one job and try to start time on another job. I'm using the
UnloadEvent on this same form to pop up when they close out of
the database. It works well for one record if I fill in the
stop time, but it allows me to close when there are other
records with stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before
exiting db, I would appreciate hearing them.
 
P

Pam

Allen,

Thank you for your help and patience in working with me on this. I've
decided to have a form open when the application is logged off listing all
those still using the system. The current user shutting down the machine
can then verify if those users are still actually working and if not enter
stop time for them then. Probably not the best solution, but it's all I can
come up with that will allow the database to be used as it is now.
I will keep the codes and ideas you have supplied. It's given me ideas in
other areas. As always, your suggestions and strategies are most helpful.
Thanks again,
Pam
Allen Browne said:
Okay, this is opening up another whole can of worms, I think.

If you have multiple users in the same back end, and some are still
working so they validly have records with no StopTime yet, but you want to
allow the current user to close their instance of the database, but they
must enter their StopTime, you will have to track who created/is editing
each of the jobs and execute the Update query such that it updates only
the jobs relating to the user who is closing down.

As there's several steps of logic to implementing that, it's probably
getting beyond what we can do in a newsgroup posting.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Pam said:
Allen,

I'm sorry to be such a pest, but you've shown me flaws in both scenarios.
I did get both methods to work and then realized how this may not be the
most efficient solution to this problem.
The unload event on the hidden form with null StopTime forcing user to
enter stop time to exit db and StopTime automatically filled in when db
is shut down thru update query would be a problem if the db were shut
down before quitting time for any reason - all time would be stopped
while work continued.
I have two computers set up in two separate shops. I thought a form to
pop up listing all those still logged on. If a user knew someone had
left, they could stop their time then. I set a command button on
switchboard to open this form if StopTime was null, disable the "x" in
the upper right corner, but if users are still working I can't come up
with a solution to close (bypass) the popup and shut down one computer
while the other is still on.
I'm open to any suggestions you may have. Once again, thank you for your
time and help.
Pam

Allen Browne said:
Sorry, Pam: the idea is to close the bound form first, since it could be
dirty with a record that needs to be saved in the same table.

I'm sorry for being slow. Where would I put this code if I close the
hidden form first?



The update query is dead easy:
strSql = "UPDATE Table1 SET StopTime = Now() WHERE StopTime Is
Null;"
dbEngine(0)(0).Execute strSql, dbFailOnError

You probably want to close the form first (so as not to get
concurrency problems.)

Allen,

I'm sorry for the confusion. Based on your statements below, I'll
try to clarify.

I do have two forms.
- a form where users enter jobs
Yes, they enter name, start time, and type of work performed for
selected job number.
- a hidden form where you are trying to prevent them closing the
database if the job lacks a close time.
Yes, it is hidden and is used so that when they start another job it
will popup reminding them they are still logged on with start time
entered and stop time empty. I wanted to use this same form when
they close the database.
So you already have the jobs entered and saved without a close time,
Yes, the user logs onto a specific job, clicks all necessary info
including start time and logs off to start work on shop floor. When
user completes task, he is supposed to come back to computer and
select his name and job number and it will open form to enter stop
time.
But this is where the problem is, some will leave for the day without
logging off the computer and time continually runs until the next
time they log on. They click stop time, which is set to Now() with
double click, and never bother to tell anyone until it shows up on
some report a month later.

An alternative approach might be to exeute an Update query that sets
the StopTime to Now() for all records where it is null.
I had originally thought about this, searched thru posts and came up
with the Unload event for hidden forms and since I already had one in
place for catching between jobs why not use it for when the computer
is shut down.

Can you tell me how to set up the Update query (I've only rarely used
them) to set StopTime to Now() upon closing? I like this idea better
anyway.


If this is a multi-user database, there is also the question of how
you identify the correct records that each user must fill in before
they can close.
I don't care if whoever shuts down the computer in the evening is the
one to log off another user's time, as long as it doesn't run for
days (like thru the weekend).

Thanks again for your help,
Pam


Okay, I'm a bit confused here.

Reading back through your thread, it seems you have 2 forms:
- a form where users enter jobs
- a hidden form where you are trying to prevent them closing the
database if the job lacks a close time.

So you already have the jobs entered and saved without a close time,
and you are now trying to insist that the database cannot be closed
unless the user goes back and adds a close time to those jobs?

If that's the idea, your hidden form would do something like this:

Private Sub Form_Unload(Cancel As Integer)
If Not IsNull(DLookup("ID", "JobTable", "[StopTime] Is Null"))
Then
Cancel = True
MsgBox "You must enter a Stop Time in all records before you
can close the database."
Docmd.OpenForm "frmJob",, "[StopTime] Is Null", _
WindowMode:=acDialog
End If
End Sub

This kind of thing bothers me: I think there is a temptation to just
crash out of Access or turn the computer off rather than enter all
the required data. As you probably know that's a good way to corrupt
the database. An alternative approach might be to exeute an Update
query that sets the StopTime to Now() for all records where it is
null.

If this is a multi-user database, there is also the question of how
you identify the correct records that each user must fill in before
they can close.

Allen,

Your last comment stated "so you are notified that the record was
not saved". I don't want the user to see a message that the record
was not saved with an "ok" button to press. These users will press
okay and go on about their business. I want them to be required to
put time in the "StopTime" field for any jobs left running before
quitting the database.

Far be it from me to question your suggestions (most of this is
Greek to me anyway), but will you please explain the posts I've
read about using a hidden form with the Unload event for anything
that has to do with procedures before closing a database. I really
thought I was headed in the right direction.

I appreciate your help and time.
Pam


I presume that prevented the bad records being saved to the table,
but it failed to report this to you.

That's a long-standing bug in Access. For details, see:
Losing data when you close a form
at:
http://allenbrowne.com/bug-01.html

The solution is to add code to the command button that closes the
form to explicitly save the record before you close the form. That
generates a trappable error, and so you are notified that the
record was not saved.

Allen,

Thanks for replying. I used the same code that I listed in my
first message and applied it to the BeforeUpdate event procedure
and tested with two open "StopTime" entries and closed the db.
It didn't catch that these two entries were not complete before
closing.

Do you have any ideas or suggestions?
Thanks again,
Pam


Use the BeforeUpdate event procedure of the form (not text box),
rather than the form's Unload event.

UnLoad is too late: by that stage the bad record has already
been saved.

Hi,

I'm trying to get users to fill in stop time on a time tracking
database before closing database. I have a hidden form that is
used as a popup when they forget they have start time entered
on one job and try to start time on another job. I'm using the
UnloadEvent on this same form to pop up when they close out of
the database. It works well for one record if I fill in the
stop time, but it allows me to close when there are other
records with stop time still open.


Private Sub Form_Unload(Cancel As Integer)
If IsNull([StopTime]) Then
Cancel = True
DoCmd.OpenForm "fWorkLogHiddenOpen"
Me.StopTime.SetFocus
End If
End Sub

If anyone has any suggestions to close all open jobs before
exiting db, I would appreciate hearing them.
 

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

Top