Restrict the number of records entered in form

Please use your words. Don't make me open the database to try to figure out what you did.
Yes, my dearPat Hartman. What I understood from you is that I am using the code in the BeforeUpdate event.
 
The code you posted was not what I suggested. Did you change it and put it in the correct event? AND only apply it in the case of a new record?
 
The code you posted was not what I suggested. Did you change it and put it in the correct event? AND only apply it in the case of a new record?
Yes dear, follow the topic from #4
 
You can't go to a new record when you are on a new record. Add error handling.
Code:
Private Sub CmdNewRec_Click()
On Error GoTo ErrProc
DoCmd.GoToRecord , , acNewRec
ExitProc:
    Exit Sub
ErrProc:
    Select Case Err.Number
        Case 2105   'already on new record
        Case Else
            MsgBox Err.Number & "--" & Err.Description
            Resume ExitProc
    End Select
End Sub
 
You can't go to a new record when you are on a new record. Add error handling.
Code:
Private Sub CmdNewRec_Click()
On Error GoTo ErrProc
DoCmd.GoToRecord , , acNewRec
ExitProc:
    Exit Sub
ErrProc:
    Select Case Err.Number
        Case 2105   'already on new record
        Case Else
            MsgBox Err.Number & "--" & Err.Description
            Resume ExitProc
    End Select
End Sub
Yes, that's great, it worked out great. Thank you very much Pat Hartman

I have a question to inquire. What is the difference between putting the code in the BeforeInsert event or putting it in the BeforeUpdate event?

332.PNG
 
Last edited:
I have a question to inquire. What is the difference between putting the code in the BeforeInsert event or putting it in the BeforeUpdate event?
I explained that. The BeforeInsert event runs before any data is placed in form controls so since you are using the ID in your test, the ID isn't available until AFTER the BeforeInsert event finishes. If you didn't need ID, then you could use the BeforeInsert event.
 
you can also use New Record button.
 

Attachments

I wouldn't worry about a user entering 21 items.

Could you check on starting whether the table is now "full", ie >=20 items, and don't let them add new ones at that point.
 
But what happens when there are only 17 so far today?
 

Users who are viewing this thread

Back
Top Bottom