PacketRat
01-05-2002, 02:29 PM
I'm interested in creating in-form buttons that control the addition, deletion and editing/updating of records individually. For example, I'd like to have a form for adding new records that has three control buttons on it: One to "Add" the new record, one to "Clear" the already entered information and start afresh without having added a bogus record to the database and a "Cancel" to close the form without having added any records, regardless as to whether or not data was entered or not. If you could guide me in the right direction, I'd appreciate it. I think its obvious I'm a newbie http://www.access-programmers.co.uk/ubb/wink.gif
jwindon
01-05-2002, 02:41 PM
First of all, the form will need to have protection set to NOT allow the user to exit the currrent record WITHOUT selecting one of the three buttons. This would involve:
1) Setting the forms record property cycle to current record only;
2) NOT showing the close button (the one next to maximize and minimize) on the form (found in form properties format);
Then, the "Add Record" button should be coded to save the current record. (I would name the button "Save Record" instead and perhaps add a fourth button to "Add Record" which would go to a new record in the form.
The Clear and Cancel button should be coded to an OnClick event to: Me.Undo. (found in the command button's properties, event tab)
That should get you started. Good luck.
Ps. In addition, a command button will need to be put on the form to Close the Form.
[This message has been edited by jwindon (edited 01-05-2002).]
PacketRat
01-05-2002, 03:42 PM
Lovely. I thought maybe, just maybe there'd be a way to do all this without coding... I should have known :p
PacketRat
02-26-2002, 11:42 AM
Alright, I'm getting into this again (I'm sick, so I have nothing better to do). Can someone give me some more specific coding examples of how I would make each of my forms have buttons that controlled whether or not the record was added, updated or cleared without adding?
I have two kinds of forms in my database as of now; Forms for adding information and forms for editing information. I would like the forms for adding records to have a button for "Add Record" and a "Cancel" button. I would like the forms for editing records to have a button for "Update Record" and also a "Cancel" button.
http://www.access-programmers.co.uk/ubb/wink.gif THX
Nothing better to do? Now that does sting!
In design view Access gives you a handy little command button wizard (make sure you wizard's wand is depressed - sunk, not unhappy). Using the command button wizard gives you lots of options to select from and Adding a new record is one of them, it will do all the hard work for you. Just have a look at all the options until you find the one you want.
I think it includes a Save Record option as well in the wizard.
To do a command button to Cancel an event without saving, again create a command button without using the wizard, double click the command button in design view and open the properties box. Select the Event tab and double click the OnClick event the code should open up. The cursor will be positioned between the line beginning Private and the line which says End Sub. Type:
Me.Undo
That will undo any changes the user has made to the record when they click the button - provided something hasn't saved the record first - but that's another matter that we can come back to.
Hope that gets you started and that you feel better soon.