MS Access – Limit the Number of Records Input in a Form

Have you ever wanted to limit the number of records that could be input into a table through a form? Simply input the following Form Current Event!

Private Sub Form_Current()
    Dim intMaxNumRecs as Integer
 
    intMaxNumRecs = 5 'Max Number of Records to Allow

    If Me.NewRecord Then
        With Me.RecordsetClone
            If .RecordCount > 0 Then
                .MoveLast:  .MoveFirst
                If .RecordCount >=  intMaxNumRecs Then
                    MsgBox "Can't add more than " &  intMaxNumRecs & " records in the demo database!"
                    .MoveLast
                    Me.Bookmark = .Bookmark
                End If
            End If
        End With
    End If
End Sub

Leave a Reply









Spam protection by WP Captcha-Free