Allowadditions on/off

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear Sir/Madam,

I have a table with a field (type character)

I created a form with the form property allowadditions = no
When the recordset.recordcount = 0 there is code that add a new record to
the file whith the value "."
ALso i have a button in the form witch add a new record
the code is
Me.Form.AllowAdditions = True
Me.Form.Refresh
Me!City.SetFocus
DoCmd.RunCommand (acCmdRecordsGoToNew)
Me!City.SetFocus

and the property AfterInsert Property of the form has the following code:
Me.Form.AllowAdditions = False

My problem is that when i click then add button for first time it works, but
the second time when i click to add a new record it appears a message "This
action is not available now".

What can i do about it?
 
Have you saved the current record you just entered or edited before you
click the button again? If not, I suspect that changing AllowAdditions isn't
allowed while the form is dirty, particularly if you're on a new record.

Also, you say that you placed the AllowAdditions = False in the "AfterInsert
Property". Did you place this directly in the Properties dialog box or did
you set it to Event Procedure and place the code in the VBA module?

To save the record, before the AllowAdditions = True statement try

If Me.Dirty Then Me.Dirty = False

This will force a save of the current record before the code gets to the
AllowAdditions statement.


If you want to save a little typing, instead of "Me.Form", you could use
just "Me"

Example:
Me.AllowAdditions = True
 
I wrote the Dirty before the allow addition and then problem exist

When the user typing the data in the field click the button "add new record"
but it display the message "yoy can not go to the specific record"
 
Thank you for your help.

I changed the code in the Add Buttom as the following:

Me.AllowAdditions = False
If Me.Dirty Then Me.Dirty = False
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
Me!City.SetFocus

now it works.
 
Back
Top