?
Solved

Limit number of records for each person filling out a form

Posted on 2014-12-19
5
Medium Priority
?
143 Views
Last Modified: 2014-12-19
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:

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

Open in new window

0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Simon
ID: 40509140
It sounds like there are some other elements of the business rules missing from this. What if the user already has 1 or more books when they start filling out this form?

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.
0
 
LVL 38

Expert Comment

by:PatHartman
ID: 40509197
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.
0
 

Author Comment

by:SteveL13
ID: 40509202
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
0
 
LVL 38

Accepted Solution

by:
PatHartman earned 2000 total points
ID: 40509272
If Dcount("*", "yourtable", "UserID = " & Me.UserID) > 5 Then
     Cancel = True
     Me.Undo
     Msgbox "Please return a book before checking out a new one", vbOKOnly
 End If

Open in new window


Domain functions take a "where" argument so you can limit the records selected.
0
 

Author Comment

by:SteveL13
ID: 40509408
Pat... Nice!  Thanks.  That did it.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question