Spurious blank records being added

S

Stapes

Hi

I have a form Customers and a subform Bookings. The subforms Allow
Additions property is set to false and Data Entry to false.
I put a button on the Customers form, New Booking, which changes the
subforms Allow Additions property to true and Data Entry to true. If
the user now closes the form without adding any booking details, a
blank record gets created.
In order to try to prevent this, I set one of the fields in the
Booking table to required. Validation > 0. Validation message "Booking
not added".
That works fine, i.e. if the user backs out they get a message
"Booking not added". However, when I now go to enter data on the
booking form the 'Booking not added' message comes out before I start
typing.

All I actually want is to prevent spurious blank records being
created.

This must be a regular thing. What is the correct procedure?

Stapes
 
K

Ken Sheridan

It would appear that something is attempting to save the subform's current
record as soon as the user enters the subform. Is there anything in your
code for doing this? It could be in the code behind the button for changing
the subform's properties, in the subform's current event procedure or
elsewhere in the parent form or subform's modules.

Another thing to be aware of is that if you assign a value to a control in
the subform as a default, say for instance the current date is assigned with:

BookingDate = VBA.Date()

then this will 'Dirty' the subform so closing it would attempt to save the
record. This would account for the original problem, but not for the fact
that your validation rule is kicking in as soon as you enter the subform. If
you are assigning a value as a default use the DefaultValue property. This
is always a string expression regardless of the data type, so its prudent to
wrap the value in quotes:

BookingDate.DefaultValue = """" & VBA.Date() & """"

BTW don't use the # date delimiter character in this context. On systems
with non-US format, or otherwise internationally ambiguous system date
settings it will do things like changing 4 July to 7 April!

I doubt that it’s a factor in the behaviour you are experiencing, but I
wouldn't have thought there's any real necessity to set the DataEntry
property of the subform to True. Why not simply move to a new record after
setting the AllowAdditions property to True? Set focus to the subform
control and then use the GotoRecord method of the DoCmd object:

Me.BookingsSubformControl.Form.AllowAdditions = True
Me.BookingsSubformControl.SetFocus
DoCmd.GoToRecord Record:=acNewRec

Ken Sheridan
Stafford, England
 

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