Prevent entering new record thrrough blank entry in Form

G

ghadley_00

Hi,

I have an MS access form which is used in edit mode, and which displays
a set of records, and then always displays a blank record at the end of
the list. I have a button for adding new records, however some users go
to the blank record at the end of the list and fill that out, thereby
circumventing some of the functions I have performed when the add new
record button is pressed. Is there a way to prevent users from being
able to add new records through this form in ways other than using the
add new record button I have created?

Thanks,

George Hadley
(e-mail address removed)
 
A

Allen Browne

The best solution is for you to learn to use the events Access exposes to
you for your validation, rather than force the user through a narrow laneway
of a particular path that you think they should follow.

The simple solution will probably be to use the BeforeUpdate event of the
*form* (not control) to perform whatever record-validation you need to do.
This event is always fired once the user has made an entry, before it is
saved. Use the event to check for nulls in fields that should have a value,
to compare values between fields, etc. If you need to do something special
if it is a new record, test the form's NewRecord property and do it. If
things are not right, cancel the event, and the record will not be saved.

If you want to do something before the user can *start* adding a new record,
do it in the form's BeforeInsert event. For example, a subform should not
accept a new entry when the main form is at a new record too. This example
shows how to block the entry in the subform if the main form is at a new
record:
Private Sub Form_BeforeInsert(Cancel As Integer)
If Me.Parent.NewRecord Then
Cancel = True
MsgBox "Enter the main form record first."
End If
End Sub

If you must put the user in a straightjacket so that they are unable to
create a new record through any of the normal means (only through your
button), you will need to create a form-level boolean variable, set it to
True when you click the button that goes to the new record. Then test the
variable in the BeforeInsert event of the form, and cancel the event if the
insert started any other way, and reset the variable ready for next time. I
wouldn't buy your program if you did that though. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top