Cannot Add new record, then disable AllowAdditions

P

Pete

Re Access 2003 SP2

I'm probably going about this the wrong way, but;

I have a parent form with an 'Add Invoice' button to add a new blank invoice
line for the selected PO to the subform. Previously added Invoices for a PO
are locked.

I want to add a blank record on the subform and stop a another new record
appearing when the user begins to edit the first new (blank) record.
I have tried using:-

With subfrmInvoicesReceived.form
.SetFocus
.AllowAdditions = True
.AllowEdits = True

'add a new record for inputting
Dim rs As DAO.Recordset
Set rs = .Recordset
rs.AddNew
Set rs = Nothing
.AllowAdditions = false
End With

(used this method because I couldn't get DoCmd.GoToRecord , , acNewRec to
work at all with the subform - said the subform is not open)

The .AllowAdditions = false line throws up an error about the primary key
cannot contain a Null value. So presumable the AllowAdditions command is
trying to save the record at this point (before the user has finished
completing it)?

Therefore, is it possible to create a new record and immediately stop
additional records being added (only through clicking a button on the parent
form each time) to the subform when the user begins to edit the first new
record.

Many thanks.
Pete.
 
K

Ken Snell [MVP]

Use the AfterUpdate event of the subform's form to set .AllowAdditions to
False.
 
P

Pete

Thanks for the reply Ken.

I have actually done this but just wondered if there was a way to stop a new
blank record appearing when completing the initial new record.

Many thanks again.
Pete.
 
L

Linq Adams via AccessMonster.com

Don't think so! If you're entering a new record AllowAdditions has to be set
to Yes, and if AllowAdditions is set to Yes, a new record line appears when
you start to enter the new record on the previous new record line..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top