I have just done this myself for the first time and got it working.. hot off
the press!
I think an "Add Record" button is safe because the users will se quite
clearly new blank fields appearing on the form so will know they are about to
input new records. You can create another button, "CANCEL," and have it
appear on the screen after the Add Record button is pressed to make things
even clearer and failsafe (we'll see....!!!)
do this by including this in the Add Record button's onClick event:
Me.YourButtonName.Visible = true
To stop users from causing an error by potentially clicking the "Add New
Record" button again whilst already in Add Mode, position the new button on
top of the Add New button in design view, then set its visible property to no
in properties window of design view.
this new button might be labelled "Cancel Add New Record (without saving)."
Set its onClick value to the following in VBA:
Private Sub YourButtonName_Click()
If Me.Dirty Then Me.Undo
DoCmd.GoToRecord , , acPrevious
Me.[YourField].SetFocus
Me.YourButtonName.Visible = False
When the user clicks this button, the "new" record will not be deleted and
the form will go back to showing a previous record. If any changes have been
made to the blank fields in the form, they will not be saved - so a new
record will not be created. The Cancel button disappears to show the add new
record button again.
Note that this works in a single form - I'm not sure if it would work in a
continuous form (although it might....) but the potential problem is that it
might undo any changes to other records in the subform (not sure about
this...)
** Does anyone know how to get the form to display the record it was showing
before the "Add new record" button was pressed (ie before the form was opened
in add mode....?) This VBA doesn't seem to work (instead it displays the
first record in the table for some reason.....) Should this be working?
Maybe I've got a form resfresh happening which is stopping this....?? Let me
know if you do!**
DoCmd.GoToRecord , , acPrevious
Tom K via AccessMonster.com said:
I would like to make it harder for users to edit records, but not impossible.
Using a New Record Form or a Edit Records Form works but it seems like there
should be a better way. Using the AddRecord button that is on the form or
leaving a form that can be edited just seems like it would be to easy to
delete or screw up data by accident.
What is the best way to handle forms and not make it to easy to screw up the
data?
Tom
Darrell said:
Very nice to have that! I have always wanted to find a way to do that.
How simple and efficient. I always end up making 2 identical forms - 1
with allow edits, 1 without...or I have to use 2 Switchboard commands -
1 to open a form in edit mode, 1 to open the form in add mode.
One quick question...would there be an easy way to open a form and have
all the fields grayed out initially (I guess it's really just changing
the back color of the fields) and when they click on the "EDIT" button,
it will "ungray" them - just to show a quick visual to the user whether
they are in "Edit Mode" or not. I guess it would need to be some
additional code associated with the same button.
Thanks,
Darrell
Thanks,
Can I do this with a macro?
[quoted text clipped - 12 lines]
Tom