Timer Shows Negative and Write Conflict Error, (1 Viewer)

Mackbear

Registered User.
Local time
Yesterday, 19:45
Joined
Apr 2, 2019
Messages
168
Hello everyone! Hope you can help me. I created an Activity Monitoring System. Here are some info:
* This is a split database.
* Multiple users of about 10 people use save records simultaneously.
* There is a field showing the running time.

Problem:
* It sometimes suddenly displays running time in negative (ex: -07:-03:-06.-72)
* Getting an error "This record has been changed by another user since you started editing it. If you save the record, you will overwrite the changes the other user made." I have attached an image of the complete error message, and also a copy of the file itself (file attached is not split).

Hope you can help me in getting a fix for this.

Thanks in advance everyone!
 

Attachments

  • AMShelp.accdb
    600 KB · Views: 39
  • AMS error messages.docx
    55.2 KB · Views: 40

Mark_

Longboard on the internet
Local time
Yesterday, 17:45
Joined
Sep 12, 2017
Messages
2,111
Number 2 is easy. If user A goes in to edit a record, then user B goes in, makes a change, and SAVES it, user A will get this message.

For Number 1, can you give a better indication of what causes this behavior? Better to know where to look for this type of issue of we know what the users are doing when it happens.
 

Mackbear

Registered User.
Local time
Yesterday, 19:45
Joined
Apr 2, 2019
Messages
168
For number 2, is there anything I need to add to my code to prevent another user from making changes to existing record? Nobody should be changing existing records. It is basically timestamps of their respective activities so anything that is already saved on the table should not be modified by someone else.

For number 1, I am actually clueless, it goes off randomly. I can't see a pattern. Possibly something on my code?
 

June7

AWF VIP
Local time
Yesterday, 16:45
Joined
Mar 9, 2014
Messages
5,463
I opened your db and form is automatically opened with record in edit mode. Why do this?

If you don't want users to interact with existing records, perhaps set form DataEntry property to Yes. Or maybe use UNBOUND form.

As is, code in form Load event is changing the first record when form opens.
 
Last edited:

Mark_

Longboard on the internet
Local time
Yesterday, 17:45
Joined
Sep 12, 2017
Messages
2,111
OK, I've looked at your app and it makes very little sense to me regarding what you are actually trying to do with it. Is this for a school project or some such?
 

isladogs

MVP / VIP
Local time
Today, 01:45
Joined
Jan 14, 2017
Messages
18,209
I'm also perplexed as to the point of this.

In addition:
a) Your table has no primary key field - suggest you add an autonumber field. Each person should be working on a unique record which may prevent your write conflict error
b) whatever the purpose of the timing code it is unnecessarily complicated and you are almost identical code on each of the buttons.

First of all this line: Dim StartTime, FinishTime, TotalTime, PauseTime means all items are variant datatype which is inefficient
Declare each properly with an appropriate datatype and do it once in the form declarations section at the top
e.g. Dim StartTime As Double, FinishTime As Double ....

c) Simplify the code. For example you could possibly use
StartTime=Timer at the start & FinishTime As Timer at the end
The Timer function counts the number of seconds since midnight (to millisecond precision if you want that)
That wouldn't work at a continuous timer but it would be a lot simpler
Have a look at any of my speed comparison tests in the code repository or sample databases. I also have a simple countdown timer for which you could modify the code so it counts up from zero

d) Add the line Option Explicit as the second line of each code module

e) As for why you are getting negative values it may be that its occasionally using a previous end event and a later start event. Without going through each line of your code its hard to give a definite answer
 
Last edited:

Mackbear

Registered User.
Local time
Yesterday, 19:45
Joined
Apr 2, 2019
Messages
168
I just uploaded the form where everyone here will be able to see how it works. When I distribute the copy, the only thing the users see is the form. The tables and navigation pane are hidden. Thanks June7, I will go ahead and try the Data Entry Property.

And for the timer turning negative, I remember I thought they had the error before due to clicking accidentally the record navigation bar at the bottom, but now I have hidden it as well and still getting the negative timer from time to time.
 

Mark_

Longboard on the internet
Local time
Yesterday, 17:45
Joined
Sep 12, 2017
Messages
2,111
OK, back to the purpose of this form. Colin has listed a lot of the problems I'd seen, but I still can't figure out WHY you are doing this, let alone what your end goal is for this.

Fixes would be
1) Make sure you declare all variables AND be clear on their type.
2) Use the built in tools ACCESS gives you with a bound form and forget about writing your own.
3) Figure out what you are really trying to save/store, as it looks like you are saving calculated values in a table, something seldom a good idea.
4) Walk us through what should happen on this form, WHY, and what outputs you will have from this data.

As is it seems you've spent a lot of time trying to tell ACCESS how to behave similar to how ACCESS already behaves but rather verbosely and with omissions that cause issues.
 

Mackbear

Registered User.
Local time
Yesterday, 19:45
Joined
Apr 2, 2019
Messages
168
OK, I've looked at your app and it makes very little sense to me regarding what you are actually trying to do with it. Is this for a school project or some such?

This is to be used at the office, a tool for measuring how much time an employee consumes for each task. Each button represents the task, and I just want to have them just click the task if they are moving on to another task and then record the duration of the previous task and start counting the time for the current task. :eek::eek::eek:
 

June7

AWF VIP
Local time
Yesterday, 16:45
Joined
Mar 9, 2014
Messages
5,463
I may have edited my previous post after you read it. I think the write conflict is because form Load event is editing the first record. So if multiple people open at same time they are all editing the same record. Either set form DataEntry to Yes or change code so moves to new record row and only edits NewRecord row.
 

Mark_

Longboard on the internet
Local time
Yesterday, 17:45
Joined
Sep 12, 2017
Messages
2,111
OK, I'd do the following
1) Table should be
UserTaskID - Autonumber - Primary key
UserID - What ever you find most useful, normally I'd have a copy of the users UserID here.
DtStart - Date/Time the task started
DtEnd - Date/Time the task Ends
UserTask - What ever you find most useful, normally I'd have a copy of the TaskID here.

That's it.
Date/Time is a decimal that holds the "Date" as an integer portion and the "Time" as the decimal. Your only interested in end-start to tell how long a task took, and you really don't need to save multiple fractions individually.

If this is supposed to sit on their desktop, you can either default DtStart to NOW() on the control properties OR you can have a button that sets it to NOW( ) you press "Start task". Any of your other buttons would simply set DtEnd to NOW() and save the record. Depending on what else you may need they could then set your form up to add a new record.
 

Mackbear

Registered User.
Local time
Yesterday, 19:45
Joined
Apr 2, 2019
Messages
168
Thank you everyone for your insights, I'll try all these and I'll get back here if I encounter stuff... I really appreciate your quick responses ������
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 01:45
Joined
Sep 12, 2006
Messages
15,634
for info, the behaviour you are seeing is because access is using something called "optimistic record locking" which is really no record locking. If two users edit the same record concurrently you get the message you saw.

The alternative is to have real active record locking, which is called "pessimistic record-locking". However this probably brings even worse problems. If a user edits a record, then goes to lunch with the record locked, then no users can access the locked record. There are other circumstances that can lead to deadlock. You then have to have special code in place to recover from this situation.

In practice, the access default is the one to use, and active record locking is really only necessary in critical systems, such as banking.
 

Mackbear

Registered User.
Local time
Yesterday, 19:45
Joined
Apr 2, 2019
Messages
168
Hello everyone,

It had been a while and so far, my project is working smoothly and i just want to thank everyone for your inputs and advices, i really appreciate it! And i hope you can help me as well on another problem :):):)
 

Users who are viewing this thread

Top Bottom