Problems with DataEntry = True

  • Thread starter Thread starter Stapes
  • Start date Start date
S

Stapes

Hi

I am opening a form "Add New Job", which on load, sets its DataEntry
attribute to true. If I enter no details & close the form, a record
had been created, so I added code to delete the record if no details
had been entered. Now when I close the form without entering any
details, it deletes the current record it has just created, but
creates another one with the next sequence number.

What I want it to do is create no record if no details are added. How
can I achieve this?

Yours

Stapes
 
Are you sure it's deleting the record you just created?

The DataEntry property does not determine whether or not records can be
added: it only determines whether existing records are displayed. Try
changing it to False, and see whether the record's still there.

To control whether or not entries may be added, you use the AllowAdditions
property.
 
Are you sure it's deleting the record you just created?

The DataEntry property does not determine whether or not records can be
added: it only determines whether existing records are displayed. Try
changing it to False, and see whether the record's still there.

To control whether or not entries may be added, you use the AllowAdditions
property.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)








- Show quoted text -

Hi

No - that's not what I want. I am setting it to data entry because I
ONLY want it to do additions, not display existing records.The Job
records are linked to a Boat record, the dtails of which are filled in
from the originating form. Options to View or Edit the Jobs record are
given elsewhere in the system.

Yours

Stapes
 
Stapes said:
On 22 Aug, 13:15, "Douglas J. Steele"

No - that's not what I want. I am setting it to data entry because I
ONLY want it to do additions, not display existing records.The Job
records are linked to a Boat record, the dtails of which are filled in
from the originating form. Options to View or Edit the Jobs record are
given elsewhere in the system.

I would assume that the record is being created when the form's opened
because you have default values assigned for one or more of the fields.
Assuming you're talking about an Autonumber when you say "the next sequence
number", there's no way of reclaiming that value unless you prevent Access
from creating the record first.
 
I would assume that the record is being created when the form's opened
because you have default values assigned for one or more of the fields.
Assuming you're talking about an Autonumber when you say "the next sequence
number", there's no way of reclaiming that value unless you prevent Access
from creating the record first.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)- Hide quoted text -

- Show quoted text -

Hi

I am not interested in reclaiming the Autonumber value - I mentioned
it because Access IS deleting my current record - as required - but
then creating a next one. I want it to delete the record if there were
no details added & close the form. Full stop. Not create an extra
record.

Stapes
 
Access doesn't arbitrarily create records. If you are getting records
created when you don't want them to be it is because you have code in some
form event that is dirtying the record and that is causing Access to think
it needs to save it.

Your code should NEVER dirty a record. That means that your code shouldn't
run before the form's BeforeInsert event. The BeforeInsert event runs as
soon as the user types the first character in the form. That way, the user
can use the esc key to back out any changes he made or you can have code
that uses the form's Undo method to back out changes. You shouldn't have to
resort to deleting records.

The first place to check is the AfterUpdate event. Many people put code
here not realizing that this event runs AFTER the record is updated and so
if you dirty the record in this event, you are essentially causing an
endless loop because Access will need to save the record again to update the
info you just changed and that will cause the AfterUpdate event to run again
and dirty the record... you see where this is going? I believe that newer
versions of Access detect this recursion and break out of the loop
eventually but it could explain the creation of the extraneous records.
 
Hi

I am not interested in reclaiming the Autonumber value - I
mentioned it because Access IS deleting my current record - as
required - but then creating a next one. I want it to delete the
record if there were no details added & close the form. Full stop.
Not create an extra record.

Stapes
No you do not want to delete the record, you want to prevent the
record from being created in the first place. It's a subtle
difference, but an important one.

Access will only create the record when you exit that record, either
by closing the form or moving to another record, having
added/changed data in any control bound to the form's record source,
the table.

What you need to do is to undo any changes made to the form before
moving off that record, unless you have set a flag that the user has
actually added something to one of the form's controls. Me.Undo is
all it takes. You just need to write some code that captures any
changes that have been made by the user to prevent the me.undo.
 
Back
Top