Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2007

Tip: Looking for answers? Try searching our database.

Duplicate record numbers....

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tonybury - 09 Mar 2007 15:08 GMT
I am not sure where to post this question as it applies to multiple areas
here. I am having a problem with record numbers being duplicated. I am
calling a piece of code from a module to create a new sales order number
based upon a sql query of max(sono) from my sales table. This works great
with one exception. I am connecting this database back to foxpro tables via
odbc and when multiple users use the database and just happen to click the
submit button to write the data back to the foxpro table there is times where
they are both grabbing the same order number. Which is causing me a freaking
headache from banging my head against the wall trying to figure out a way
around it. I have put the call function to retrieve the max(sono) from the
sales table at the last step before I run the insert statement. I would have
a hard time writing a dummy record to grab the number as the table (which I
cannot modify) does not allow any of the 100+ fields to be null. I was
thinking about just using a select statement within my insert statement to
grab the last order number (max(sono)) but although I am pretty decent with
SQL I am not that advanced. I don't even know if it is possible. I only run
into this problem when two people just happen to click submit at the same
time. I have even thought about putting some type of random pause function to
get around this but there just has to be a better way that someone knows that
is more advanced than me with coding.

Please, please, please help!

Regards,

Tony
Stefan Hoffmann - 09 Mar 2007 15:19 GMT
hi Tony,

> I am not sure where to post this question as it applies to multiple areas
> here. I am having a problem with record numbers being duplicated. I am
[quoted text clipped - 4 lines]
> submit button to write the data back to the foxpro table there is times where
> they are both grabbing the same order number.
Don't know if it works with Foxpro, you need a unique constraint on your
record number field, then the insert will fail:

  Dim db As DAO.Database
  Dim i As Long

  Set db = CurrentDb
  i = 0

  db.Execute "INSERT INTO Table () SELECT Max() + 1, Values FROM Table"
  Do While (db.RecordsAffected = 0) Or (i < 5)
     i = i + 1
  Loop
  If db.RecordsAffected = 0 Then
     MsgBox "not saved"
  End If

mfG
--> stefan <--
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.