Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the AllowAdditions Property

Status
Not open for further replies.

scking

Programmer
Jan 8, 2001
1,263
US
I'm attempting to prevent users from accidently adding records by using the AllowAdditins property on the form. When they click the 'Add' button I update the AllowAdditions property to True and create a new record. They I need to turn it off in an event after the new record is created. When I set it to false in the 'Current' event I get errors managing the properties of other controls. My objective of course is simply to reset it to prevent an accidental record creation again. Any suggestions? -------------------------------------
scking@arinc.com
Try to resolve problems independently
Then seek help among peers or experts
But TEST recommended solutions
-------------------------------------
 
Hi, an easier way to accomplish your objective might be to set set required fields in your underlying table to Required = Yes.

It should accomplish the same thing.

Hope that helps
 
Not quite. All that does is give you an error if you don't complete the field. Since this is a commercial quality database it really needs to handle these issues without the user having to hit the ESC key to undo a partially created record. That is currently what it has but whenever you nagicate to a newer record with the cursor in one of the subform fields it will automatically start a record. Then when they attempt to move to the next they will get the error.
-------------------------------------
scking@arinc.com
Try to resolve problems independently
Then seek help among peers or experts
But TEST recommended solutions
-------------------------------------
 
Ok, if there is a button in the subform to save the record then after the click on save you could do something like:

Forms!yourform.SetFocus
Forms!yourform.AllowAdditions = False

To re-enable records on a button in the main form before adding a new record on click:

Forms!yourform.AllowAdditions = True
 
Which is what my original write-up says I do BUT "When I set it to false in the 'Current' event I get errors managing the properties of other controls." As soon as I removed the 'Me.AllowAdditions = False' these errors evaporated.

-------------------------------------
scking@arinc.com
Try to resolve problems independently
Then seek help among peers or experts
But TEST recommended solutions
-------------------------------------
 
Well, maybe I'm missing something here but your object seems to be to disable allow additions after a record has been saved. I don't see where this has anything to do with On Current event. The event fires after a record has been saved, not on current. It in whatever control you are using to save the record, after you've saved the record:

On Error GoTo Err_Command47_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
***Forms!yourform.SetFocus
***Forms!yourform.AllowAdditions = False
Exit_Command47_Click:
Exit Sub
 
The Current event is fired whenever you navagate to a new record. So it fires after you have saved a record and prior to actual display of the form. In the past I've used it successfully to 'SetFormState' and perform these type functions. We DO NOT have a save button since the forms are connected to the data it is not necessary. I believe either the 'Click' or the 'Current' button should be able to set the .AllowAdditions property on the form. I would rather get the 'Current' event working because data entry clicking 'Save' then 'Add' is two separate keystrokes vs either navigating to the next record or 'Add' which would both be one stoke handled by the 'Current' event.

I have this thing working using flags and the 'Current' event but don't like the design and it can be problematic.

Thanks for your suggestion. I might try it out but like to change the state of the buttons depending on the form. For instance, if not Me.Dirty then the 'Save' button is disabled. If I were to use the 'Save' button design I would necessarily have to remove the default navigation buttons and put some logic behind the developed navigation buttons to determine if the 'Save' button were enabled to prompt the user to save or discard.

-------------------------------------
scking@arinc.com
Try to resolve problems independently
Then seek help among peers or experts
But TEST recommended solutions
-------------------------------------
 
Ok, one final suggestion. I played around with it a little more and put the allow additions code in the After Update of the last text box. Tried it in a sub form and on the main form. I could turn on and off allow additions doing it that way as well. No buttons required. You might give that a shot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top