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
numerazione automatica
-
- Administrator
- Posts: 78558
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: numerazione automatica
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
Hans
-
- PlatinumLounger
- Posts: 4364
- Joined: 26 Apr 2010, 17:36
Re: numerazione automatica
HansV wrote: ↑13 Jun 2021, 14:03In 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