Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Set a Maximum amount of Records on a Form

Status
Not open for further replies.

mpsDA

IS-IT--Management
Jul 27, 2005
43
GB
How do you set a Maximum number of Records for a form to be entered. i.e i do not want the user entering more than 20 records for this form permanently. also if the user tries to enter more than 20 records an error message should appear explaing why and what to do.

Can this be done??
 
It is depending to the way you choose.
You can either use DCount Function to check the table if it has already 20 numbers of records

or
to use Me.RecordsetClone.RecordCount

Dcount is best
Code:
If DCount("*", "TableName")< 20 then
'....Go to new Record...
Else
MsgBox "No More"
End If
code not tested

________________________________________________________________________
Zameer Abdulla
Visit Me
Children are poor men's riches.
 
There was some mistake in the previous code. here is the correct one.
Code:
Private Sub cmdAddNew_Click()
    If DCount("*", "TableName") >= 20 Then
        MsgBox "No More"
    Else
        DoCmd.GoToRecord , , acNewRec
    End If
End Sub

If you are doing something like Invoicing you may need to check the count of current records.
Like.. Suppose you allow only 20 items in an Invoice. You need to check if it is 20 records
Code:
Private Sub cmdAddNew_Click()
    If Me.RecordsetClone.RecordCount >= 20 Then
        MsgBox "No More"
    Else
        DoCmd.GoToRecord , , acNewRec
    End If
End Sub

________________________________________________________________________
Zameer Abdulla
Visit Me
Children are poor men's riches.
 
Perhaps use the on current event? Another property to use might be the allowadditions property - this will alter the navigationbuttons in a way that indicates that new record isn't available.

[tt]me.allowadditions = (me.recordsetclone.recordcount < 20)[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top