Hello, all. I am new to this forum and have a question about a database I created last year for our family business. It is a split database with about 12 user stations and all data is manipulated through forms and VBA code. I am self taught over the years but this database is larger and has more users than any in the past so I am running into "new" issues in regards to muliple user access at the same time. The database is for part tracking, a "move ticket" number is assigned when an item is received or created. The numbering system for both received items (our raw goods) and the created items (our finished goods) is the same. Basically, I have a temp table that stores the last ticket number used (tblTICKETREF). When a user wants a new ticket it looks at that temp table, updates that record by incrementing that number up by one, then prints a ticket using that number. If the user is requesting more than one ticket then it loops for a designated number of times. All works good, except about once a month I find duplicate ticket numbers in the system. It seems to happen when two stations are accessing that temp table (tblTICKETREF) at the same time and both end up being assigned the same number. I am looking for a solution that would pause or lock one of the users until the code has finished for the other, or a better method if this one is subpar. The code loop is below. Any help would be greatly appreciated.

Sincerely,
Mark

'begin loop for the desired number of tickets
Set mydb = CurrentDb
Do Until i = 0


'find the next move ticket number
'from the tblTICKETREF table
ticktemp = DMax("[TICKETREF]", "tblTICKETREF")
ticketnew = ticktemp + 1

'Update the ticketref field, increment it by one
mydb.Execute "update tblTICKETREF set " _
& "[TICKETREF]= " & ticketnew & ""

'insert new record into tblTicketTempProd, the temporary table for tickets
mydb.Execute "INSERT into tblTickettempProd ([ticketno], [item], [qnty], [batchdate]) values (" _
& """" & ticketnew & """, " _
& """" & Me.ProductID & """, " _
& """" & Me.txtPartQnty & """, " _
& """" & mydate & """) "

i = i - 1