UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Unique Number, Office 2007    
 
   
mefrogs8
post Apr 10 2012, 08:53 AM
Post #1

New Member
Posts: 11



Ok I am new to the access 2007 database. I need to generate a unique number series for control and have them increment by 1 starting with 0001 and to be able to assign this number at save time on my form. There will be other users and I want to prohibit deletions and prohibit cancelling the form so that the numbers don't repeat themselves. I don't want duplicate numbers and I know there have been alot of discussions on using the autonumber but this will not work if there are other people creating a new record on the form at the same time and then they will get the same number. Do I have to create another form or table from which to pull these numbers from or can I just do an expression? I am not entirely sure on how to do this. Any help will be very much appreciated. Thank you!
Go to the top of the page
 
+
Bob G
post Apr 10 2012, 09:00 AM
Post #2

UtterAccess VIP
Posts: 8,131
From: CT



if you are going to prevent cancelling then once the number is given it would be used. You can create a field in your table that is a number. Then use the DMAX function to get the highest number used and add 1
Go to the top of the page
 
+
GroverParkGeorge
post Apr 10 2012, 09:04 AM
Post #3

UA Admin
Posts: 19,240
From: Newcastle, WA



Autonumbers are not good for this purpose in any event.

There have been a number of methods for generating unique numbers uploaded here, including this one.
Go to the top of the page
 
+
arnelgp
post Apr 10 2012, 09:06 AM
Post #4

UtterAccess Ruler
Posts: 1,090



On multi user db you can use this code:

Create a table: tblNextSeries (fNextSeries Long)


CODE
Public Function fGetNewNum() As Long
    On Error GoTo Error_Handler
    Dim rstID As dao.Recordset
    Dim lngID As Long
    Dim intRetry As Integer
    Dim db As dao.Database
    Set db = CurrentDb
    Set rstID = db.OpenRecordset("tblNextSeries")
    If rstID.EOF And rstID.BOF Then
        ' No records yet, start with one
        lngID = 1
        With rstID
            .AddNew
            !fNextSeries = lngID
            .Update
        End With
    Else
        ' Edit the existing record
        rstID.MoveFirst
        lngID = rstID!NEXT_MRR_NO + 1
        With rstID
            .Edit
            !fNextSeries = lngID
            .Update
        End With
    End If
    fGetNewNum = lngID
Exit_Here:
    On Error Resume Next
    rstID.Close
    Set rstID = Nothing
    Set db = Nothing
    Exit Function
Error_Handler:        'If someone is editing this record trap the error
    If Err = 3188 Then
        intRetry = intRetry + 1
        If intRetry < 100 Then
            Resume
        Else    'Time out retries
            MsgBox "Another user editing this number", vbOKOnly, "Please Wait"
            Resume Exit_Here
        End If
    Else    'Handle other errors
        MsgBox Err.Number & ": " & Err.Description, 48, "Problem Generating Number"
        Resume Exit_Here
    End If
End Function
Go to the top of the page
 
+
mefrogs8
post Apr 11 2012, 09:26 AM
Post #5

New Member
Posts: 11



Thanks for your responses! I will try these and will let you know which one works with what I am trying to achieve.
Go to the top of the page
 
+
mefrogs8
post Apr 13 2012, 02:19 PM
Post #6

New Member
Posts: 11



Thanks arnelgp for your help however, I am a little confused. I created a new table: tblNextSeries but I don't know what you mean by (fNextSeries Long) and I don't know where to put the code and how this relates to my quote sheet where I need create the unique number series where it starts with 0001. Thanks!
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 22nd May 2013 - 09:54 AM