CodeDocu.com

Access vba: Create updating default values

 

 

Task:

In an input field, the default values for new lines should automatically correspond to a counter or consecutive numbering

 

Solution:

In Vba the entered value is determined. From this one calculates whether there is a separation point and then increases the right part from the separation by increasing the ASCII numbers.

 

Update of numbering using Ascii

'*.a or .1

Next_Letter = Chr(Asc(sExt) + 1)

 

Access vba: Create Numbering as default values

 

 

Solution code in Visual Basic for Applcations vba.

Used in Microsoft Access all versions

Private Sub ctlPosition_AfterUpdate()

    '--------< ctlPosition_AfterUpdate() >--------

    '< check input >

    Dim sInput As String

    sInput = Nz(ctlPosition.Value, "")

 

    Dim posPoint As Integer

    posPoint = InStr(1, sInput, ".")

    '</ check input >

 

    If posPoint > 0 Then

        '----< Has .Point >----

        Dim sExt As String

        sExt = Mid(sInput, posPoint + 1)

        If Len(sExt) = 1 Then

            '--< Single Extension >--

            '*.a or .1

            sExt = Chr(Asc(sExt) + 1)

            Dim sFront As String

            sFront = Mid(sInput, 1, posPoint)

 

            '< set Default >

            ctlPosition.DefaultValue = "'" & sFront & sExt & "'"

            '</ set Default >

            '--</ Single Extension >--

        End If

        '----</ Has .Point >----

    Else

        '----< Numeric >----

        If IsNumeric(ctlPosition) Then

            '-< IsNumeric >-

            Dim sNext As Integer

            sNext = CLng(ctlPosition) + 1

            '< set Default >

            ctlPosition.DefaultValue = "'" & sNext & "'"

            '</ set Default >

            '-</ IsNumeric >-

        End If

        '----< Numeric >----

    End If

    '--------</ ctlPosition_AfterUpdate() >--------

End Sub

 

 

Simply put in the AfterUpdate event.

Access vba: Create Numbering as default values


Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel