Restrict Data Entry

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

I have a Data Entry form that is based off of a table. I also turned off the
record selectors and navigations buttons on the form. I want the user to
fill out the form and then hit an "Add Record" Command button to add the data
to the table. I have all of this working except I ran into a problem. The
problem I have is that when the user fills out the form the data gets added
to the table even if they don't hit the "Add Record" command button. I don't
want any data to be added to the table unless the user clicks on the "Add
Record" button. Does that make sense?

Does anyone know what I am doing wrong? I have the Data Entry property set
to Yes.

Thanks,
Andrew
 
The ways in which a user can cause a record to be saved are manifold. They
can go to a new record (which they can still do despite you hiding the
navigation buttons). They can use Shift+Enter on the keyboard. They can
even simply close the form.

Why do you want to prevent all of this? What's so crucial about your "Add
Record" button? To get the best out of Access (in terms of both
functionality and productivity), it's invariably best to work *with* it, not
to fight *against* it.

But, if you insist, you could try something like this:

First, declare a module-level Boolean varaible:

Dim mfAddButtonClicked As Boolean

In the Click event procedure for your command button, set the variable to
True:

mfAddButtonClicked = True

In the form's BeforeUpdate event:

If mfAddButtonClicked = True Then
mfAddbuttonClicked = False
<any other code you need to run before saving the record>
Else
Cancel = True
End If

This should prevent the record being saved by any means other than clicking
the command button. However, I predict that cancelling the BeforeUpdate
event will cause various error messages depending on what method was used to
attempt to save the record. You will also get an error message if the
command button is clicked but you then cancel the BeforeUpdate event as a
result of, say, a validation failure. These errors will need to be trapped
and handled appropriately in order to provide a satisfactory user
experience: such is the price of trying to radically alter Access' default
behaviour.
 
Andrew,
If you enter the data on this form and close the form using the x in top
RHS, the data will be saved.
If you wish to cancel adding the data to the table, you need a cancel button
and a save button on the form and hide the x in top RHS.
User can either click the save button or the cancel button to close the
form.
The save button has code something like this:
If Me.Dirty = True Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name


The cancel button has code something like this:
If Me.Dirty = True Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name


Make sure users can't close the form with Alt + F4 or Ctl + F4 or any other
way.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

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

Back
Top