SteveL13
asked on
Limit number of records for each person filling out a form
I have a form which users use to enter records. For each person filling out the form they are "assigned" a userID automatically which is a text ID. The table also of course has a RecordID autonumber field.
Anyway, as the user is filling out the form, which is really a sub-form (continuous form), and have entered 5 records and attempt to enter a 6th record, I want a message to popup informing them that they can't enter any more records.
Something like this but I don't know how to qualify the userID:
Anyway, as the user is filling out the form, which is really a sub-form (continuous form), and have entered 5 records and attempt to enter a 6th record, I want a message to popup informing them that they can't enter any more records.
Something like this but I don't know how to qualify the userID:
Private sub Form_BeforeInsert(Cancel as Integer)
If Me.txtCount > 5 Then
Cancel = True
Me.Undo
Msgbox "Please return a book before checking out a new one", vbOKOnly
End If
End Sub
Ideally, you'd want to warn them that they can't fill it out again BEFORE they do so rather than undoing it after they've filled it in.The BeforeInsert event runs after the FIRST character is typed into a new record so the user hasn't expended any energy at this point. This is the correct event to use.
Use DCount() instead of a saved count field. Saving counts, sums, etc. causes data anomalies and requires extreme care to keep in sync with the actual count or sum. It also must be handled at the form level and that means that queries or outside updates from another source such as a web app aren't counted. violating normal forms is poor practice and should only be done in unique situations and with full knowledge of the potential consequences.
ASKER
I understand but I still don't know how to set the limit per UserID
Something like: (which isn't right of course)
Private sub Form_BeforeInsert(Cancel as Integer)
If Me.txtCount > 5 PERUSERIDThen
Cancel = True
Me.Undo
Msgbox "Please return a book before checking out a new one", vbOKOnly
End If
End Sub
Something like: (which isn't right of course)
Private sub Form_BeforeInsert(Cancel as Integer)
If Me.txtCount > 5 PERUSERIDThen
Cancel = True
Me.Undo
Msgbox "Please return a book before checking out a new one", vbOKOnly
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Pat... Nice! Thanks. That did it.
Ideally, you'd want to warn them that they can't fill it out again BEFORE they do so rather than undoing it after they've filled it in.