Search code examples
vbams-accessruntime-errorms-access-2013autonumber

Access 2013 Increment a text ID field in a form


I have created a database from an excel file, one of the columns (PK) is the license number however this is in text format XX/XX/XXXX

When a new record is created I would like the form to auto-populate the license number field with a similar ID containing both text and numbers. This has to be incremented with every new record (only the number part)

This is exactly what I want to achive however I am getting the error shown below; https://www.youtube.com/watch?v=kPz-n5w5YtE

enter image description here enter image description here

Any help would be appreciated, I have experience with VB however I am familiar with other programming languages.


Solution

  • If your idea is to take a number (8) and convert it to "0008", as in the comment above the error, try like this:

    strNextNumber = Format(lngNextNumber, "0000")
    

    or see the whole code:

    Public Sub TestMe()    
        Dim strNextNumber As String
        Dim lngNextNumber As Long
        lngNextNumber = 8
        strNextNumber = Format(lngNextNumber, "0000")
        Debug.Print strNextNumber        
    End Sub