Set AllowAdditions to false

B

Bob Quintal

HI,
I have a popup single form that gets its data from a table with
one field. I want to only allow the user to enter one new item
and then exit the form. I have the the code " DoCmd.GoToRecord
, , acNewRec" in the form open event. This sends my form to a
new record. I have a close button that closed the form and that
works fine. The problem is that if the user enters data and
presses "Enter" another blank field opens and the user can make
another entry. I tried placing "Me.AllowAdditions = False" after
the acNewRec code, but that didn't work.
How can prevent the user from making more than one entry?
Thanks,

There is a form property called Cycle (on the Other tab). Set it to
Current Record. Also set the Navigation Buttons property (Format
tab) to no.
 
G

Guest

HI,
I have a popup single form that gets its data from a table with one field.
I want to only allow the user to enter one new item and then exit the form.
I have the the code " DoCmd.GoToRecord , , acNewRec" in the form open
event. This sends my form to a new record. I have a close button that
closed the form and that works fine. The problem is that if the user enters
data and presses "Enter" another blank field opens and the user can make
another entry. I tried placing "Me.AllowAdditions = False" after the
acNewRec code, but that didn't work.
How can prevent the user from making more than one entry?
Thanks,
 
R

Rob Parker

Hi Phil,

Assuming that you don't have record selectors or navigation buttons that
will allow your user to get to a new record from your popup form, then all
you need to do is set the Cycle property for the form itself to "Current
Record" (its on the Other tab of the property dialog). This will prevent
the tab key or enter key from cycling to the next (in this case, new) record
when it leaves the final control in the tab order; instead, it will return
to the first control in the tab order.

HTH,

Rob
 
M

Marshall Barton

Phil said:
I have a popup single form that gets its data from a table with one field.
I want to only allow the user to enter one new item and then exit the form.
I have the the code " DoCmd.GoToRecord , , acNewRec" in the form open
event. This sends my form to a new record. I have a close button that
closed the form and that works fine. The problem is that if the user enters
data and presses "Enter" another blank field opens and the user can make
another entry. I tried placing "Me.AllowAdditions = False" after the
acNewRec code, but that didn't work.
How can prevent the user from making more than one entry?


You don't need to go to the new record if you open the form
with the DataMode argument set to acFormAdd

It may look a little odd, but you can use the AfterInsert
event to set AllowAdditions to False
 
M

Marshall Barton

Rob said:
Assuming that you don't have record selectors or navigation buttons that
will allow your user to get to a new record from your popup form, then all
you need to do is set the Cycle property for the form itself to "Current
Record" (its on the Other tab of the property dialog). This will prevent
the tab key or enter key from cycling to the next (in this case, new) record
when it leaves the final control in the tab order; instead, it will return
to the first control in the tab order.


All true Rob, but it would be safer to prevent all the ways
of getting to another new record. Even if there's no scroll
bar, the Page Down key will move to another record.

I do like the idea of setting the Cycle property to prevent
a screen blink when users just hit Enter or Tab though.
 
R

Rob Parker

Hi Marsh,

Thanks for that comment. You - well, actually I - learn something new all
the time. I wasn't aware that the PageDown key would move to the next
record, even with Cycle set to Current Record.

Rob
 
A

Albert D. Kallal

Marshals kindly pointed out a solution but I just add more in case it wasn't
clear.

So set the form's allow additions to "no",

Then simply open the form using the acFormAdd parameter.

The result of the above is you'll get a form that opens to a new record but
even page down, mouse wheel, or anything else you use/hit will not add a new
record.

So the openFrom command actually overrides the forms setting for just the
ONE record we add, which is exactly what we need in this case.

So you can leave the form with the allow additions set to no at all times

just use:

docmd.OpenForm "nameofform",,,,acFormAdd

acFormAdd will over ride the form a setting for just the one record.
 
M

Marshall Barton

Albert said:
acFormAdd will over ride the form a setting for just the one record.


That doesn't work for me, Albert. In my tests, FormAdd
overides AllowAdditions for as many records as the user
wants to add. It's not until some code changes
AllowAdditions to False (regardless of its original setting)
that records can not be added.

I find this whole issue to be very confusing. I finally
realized that the form design must be closed and saved
before testing the effects of FormAdd. If the form is
already open in design view, opening the form with FormAdd
appears to remember the state of the form before it was
switched to design view and I could never remember what
state that was. I'm not sure I fully understand what's
going on, but if the form's design is closed and saved, then
the behavior appears to be consistent.
 

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