Adding new record

highandwild

Registered User.
Local time
Today, 11:21
Joined
Oct 30, 2009
Messages
435
I have a form with [Add] and [Edit] buttons which allow the user to Add a new record or edit the existing one.

The user can tab from the last textbox and go to a new record. This is not what I want them to be able to do.

How can I only allow them to edit the one record or just enter one new record and then for those changes / additions be saved.

Thanks
 
On the After update of the last text box close the form.

DoCmd.RunCommand acCmdSaveRecord

DoCmd.Close acForm, "YourFormNameHere", acSaveYes

Note: the acSave saves the form structure and not the data.

Dale
 
By setting the form properties AllowAdditions, AllowEdits or AllowDeletions ( if you wish to control deletions). Not sure that I type exactly but you will recognise this properties in the Property Sheet :)
 
rzw0wr

This only works when the data in the last textbox has been changed and as this textbox is not mandatory this method will not work.

Any other ideas?
 
Ok.
Your users are adding and editing on 2 different forms. Correct.
And as they finish adding a record you want to stop them from automatically going to the next new record.Correct.
If this is true then they can not get to a new record without putting the cursor in the last text box and hitting enter.

Dale
 
Please see the attachment.

The user selects the Edit or Add buttons and the text boxes are unlocked and the cursor placed in the first text box or if a record is being added the new record is added using

DoCmd.GoToRecord , , acNewRec

and the cursor placed in the first text box.

The buttons on the bottom are enabled / disabled as appropriate depending on the current mode.

When the user tabs from the Town field I would like the record to be saved and then for the code to resume control.

Thanks for any ideas.
 

Attachments

  • screen.png
    screen.png
    98.5 KB · Views: 74
OK, that helped.
You want to let them add or edit 1 record only correct.

In the On Click code for both buttons add the following as the last lines of code.

me.YourButtonNameHere.Enable = False

When they click the button 1 time this will turn the button off.

Dale
 
I do not have a problem turning the button off.

The Edit button unlocks the textboxes, comboboxes etc to enable the data to be edited.

The Add button creates a new record using

DoCmd.GoToRecord , , acNewRec

and enables the user to enter the new record.

I just want the user to Edit the current record without going onto a new one when they tab past the last textbox and to be able to add a new record without the same problem arising.
 
Then what is wrong with post #2?

Dale
 
To work it demands that data has been entered into the last textbox which will not always happen.
 
Try this in the last text box Lost Focus event.

Code:
DoCmd.RunCommand acCmdSaveRecord

MsgBox "you can not add or edit more records", vbOKOnly
Me.YourFirstTextBox.SetFocus
This will not let you go past the last text box either empty or after entering data.

Dale
 
If you switch the Cycle of the forms properties to 'Current Record' this will stop the user being able to tab off the current record.
 

Users who are viewing this thread

Back
Top Bottom