Access- AutoID format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smugcool
    New Member
    • Apr 2007
    • 81

    Access- AutoID format

    Hi All,

    I m have stuck in at a place, Where i want to generate a ID something like "CRC-CC-1009-001".Where

    CRC-CC- will remain common for all generated id's
    1009- system date
    001- incremental order number for the system date.

    as if date will change it will start count from 001.

    How to customize the fomat for AutoID.
    Please help me.
  • Kevin Wilcox
    New Member
    • Sep 2007
    • 68

    #2
    I don't think you can customise autonumber, I had the same issue recently. I resolved it by customing the format of the field in the relevant forms and reports, adding in the prefixs that I wanted

    Comment

    • smugcool
      New Member
      • Apr 2007
      • 81

      #3
      Originally posted by Kevin Wilcox
      I don't think you can customise autonumber, I had the same issue recently. I resolved it by customing the format of the field in the relevant forms and reports, adding in the prefixs that I wanted
      ok...thanx kevin for your quick response...but how u did it in form....or just give me some idea how should u i go forward in my case.

      Comment

      • damonreid
        Recognized Expert New Member
        • Jul 2007
        • 114

        #4
        [code=vb]Private Sub IDCode_AfterUpd ate()
        Dim strProdCode As String

        If Me.NewRecord Then
        strProdCode = Me.IDCode.Value
        ' Increment the IdentNumber field by One, if field is Null, set as 0 then add 1
        Me!IdentNumber = Nz(DMax("Right( Identifier,4)", "IDCodeQuer y"), 0) + 1
        Me!Identifier = Me.IDCode.Value & "-" & Format(Me!Ident Number, "0000")
        Else
        Me!strID = Me!strID
        End If

        End Sub[/code]
        This makes a unique number with the pre-field IDCode then a - then the next avilable number in the format 0000.
        IDCodeQuery is only used to get the next avilable number because the pre-field code can change. You want the DMax and Right or Left codes to do what you want to do.

        Comment

        Working...