473,396 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Preventing two users adding a new duplicate record

121 100+
Hi

I have an shared application with a front and back end which is designed to book equipment to a room at a date and time specified by the user so the user will be able to create a record as follows

User 1

Item 1 room1 1/1/2011 09:00 - 1/1/2011 12:00

I have some code to check to see if item 1 is booked anywhere else between the time and dates specified above.

So if user 2 has it booked elsewhere as follows it will not allow user 1 to create the new record

User 2
Item 1 room3 1/1/2011 10:00 - 1/1/2011 12:00

So if user 1 tries to create a new booking for item 1 a message will say the equipment is already booked


I have tried to book item 1 on two machines simultaneously by clicking the book item button at the same time on both machines which resulted in a double booking of item 1 which is what i want to avoid.

Record locking will not work in this scenario because I am creating a new record (unless I am missing something )

It is pretty unlikely that two users will book exactly the same item at the exactly the same time but is there anyway i can prevent this from happening?

any help is much appreciated

Regards Phill
Dec 7 '10 #1
5 2082
pod
298 100+
Maybe you could add an extra step to the booking process; add a confirmation step once the record is created which checks for duplicates, and have it take the appropriate action such as advising the duplicater that his record will be deleted...
Dec 7 '10 #2
patjones
931 Expert 512MB
Hi Phill,

One way to resolve this might be to use table-level locking so that only one record can go in at a time.

The disadvantage to table-level locking of course is that multiple users won't be able to access the table at the same time, which is a problem if you have a large number of users needing constant access.

Another thing you could try is having Access assign an auto-number primary key to new records, and set the table's design to prohibit duplicate keys. If Access is really adding these records concurrently, it should raise an error preventing one or the other record from going in on account of the primary key constraint.

This is my first post after a taking a little break from the site, so I'm a bit rusty in terms of responding to questions. I hope this gets you started though.

Pat
Dec 7 '10 #3
phill86
121 100+
Hi Thanks for the suggestions unfortunately the table locking is not an option as I will have several users needing access to the table at the same time.

An extra step seems like a good idea but i opted for a random time delay when the book item button is pressed this will make it even more unlikely that two users will book the kit at the same time.



Thanks for your help
Expand|Select|Wrap|Line Numbers
  1. Dim MyValue
  2. Dim PauseTime, Start, Finish
  3. Dim TotalTime As Single
  4.  
  5.  
  6.  
  7. Randomize    ' Initialize random-number generator.
  8.  
  9. MyValue = Int((4 * Rnd) + 1)  ' Generate random value between 1 and 6.
  10.  
  11.  
  12.  Start = Timer    ' Set start time.
  13.     Do While Timer < Start + MyValue
  14.         DoEvents    ' Yield to other processes.
  15.     Loop
  16.     Finish = Timer    ' Set end time.
  17.     TotalTime = Finish - Start    ' Calculate
  18.  
  19. End Function
  20.  
Dec 8 '10 #4
patjones
931 Expert 512MB
Hi,

I agree that it is extraordinarily unlikely that a concurrency issue would arise using this method...but still bear in mind that it could.

Just a quick question...what do you do with TotalTime after calculating it?

Pat
Dec 8 '10 #5
phill86
121 100+
Hi Pat

Not actually using the time to calculate totals just using the time values to see if the item is booked elsewhere between 09:00 and 12:00 for example and if it is that means that it is unavailable to book.

Cheers Phill
Dec 8 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mark | last post by:
When my form goes to a new record, I have a procedure that copies the last record added to the form's underlying table into the form. The intent is that a series of new records may have the same...
2
by: Mike N. | last post by:
Hello again.. I have a table with a text field named "Requisition" (Indexed, no dupes). It is not the key field. This field is the first text box on a form. I would like to check to make sure the...
0
by: Cyberwolf | last post by:
OK, how to explain this. I have a table that will feed into another table using an append query. What I want to do is look at the table I am appending the record to to check for a duplicate...
1
by: 2D Rick | last post by:
Access2003 in XP If I open a form to a specific record and click on a command button with the following code I get a duplcate record: DoCmd.RunCommand acCmdSelectRecord DoCmd.RunCommand...
0
by: Antonio | last post by:
Hello, everyone. Something strange is happening when I edit a record in the datagrid. I have a cust_id field that, when the grid is in edit mode, users can change. I don't really want to display...
1
by: Catriona | last post by:
I am developing an Access application where users insert bill records for an electricity account by clicking on a new button. The required workflow is 1) New button clicked 2) New record appears...
1
by: pcnorb | last post by:
I have a form, pulling data from a Products table that has many fields that do lookups to other tables. These are in a one-to-many relationship to a pk in each of said tables. I'd like to be...
1
by: raaaz | last post by:
Hi All, I am having a totaly different sort of problem which is out of my efforts now so may be any one out of you might help me out of this. I am using very simple code below to add a record...
2
by: Ranma13 | last post by:
Hello, I have a duplicate record check written in VB for a check in/check out database. Here's the pseudocode, written for the BeforeUpdate property on the form: If DCount(search for records with...
3
by: JMANTN | last post by:
Hello, I'm hoping someone could help me out with a problem I've ran into while trying to create a training database. I'm just a beginner with Access and VBA so please take that into consideration. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.