numerazione automatica

User avatar
sal21
PlatinumLounger
Posts: 4336
Joined: 26 Apr 2010, 17:36

numerazione automatica

Post by sal21 »

I need to set the first filed in table, access ide, with this format:

CLI0001
CLI0002
...
CLInnnn

where CLI is a fixed value and 0000 is automatic increment of key

User avatar
HansV
Administrator
Posts: 78359
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: numerazione automatica

Post by HansV »

In Access, run this code:

Code: Select all

Sub NumAut()
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim i As Long
    Set dbs = CurrentDb
    ' **** Change MyTable to the name of your table ****
    Set rst = dbs.OpenRecordset("MyTable", dbOpenDynaset)
    Do While Not rst.EOF
        i = i + 1
        rst.Edit
        rst(0) = "CLI" & Format(i, "0000")
        rst.Update
        rst.MoveNext
    Loop
    rst.Close
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4336
Joined: 26 Apr 2010, 17:36

Re: numerazione automatica

Post by sal21 »

HansV wrote:
13 Jun 2021, 14:03
In Access, run this code:

Code: Select all

Sub NumAut()
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Dim i As Long
    Set dbs = CurrentDb
    ' **** Change MyTable to the name of your table ****
    Set rst = dbs.OpenRecordset("MyTable", dbOpenDynaset)
    Do While Not rst.EOF
        i = i + 1
        rst.Edit
        rst(0) = "CLI" & Format(i, "0000")
        rst.Update
        rst.MoveNext
    Loop
    rst.Close
End Sub
:cheers: