Subform Disappears when AllowAdditions=False

G

Guest

Hello All,

I have a subform that is giving me a headache. Here is my dilema.

The "allow edits", "allow deletions", and "allow additions" properties are
all set to yes on the subform itself. However, when I call the parent form
from a button, the subform becomes invisible. The noted button is coded to
set all the above mentioned properties of the subform to false. The subform
is only invisible when there is no recordsource. However, I would like the
subform to remain visible even when there is no data. The overall form looks
terrible with a huge space due to the invisible subform. The only controls I
have on the subform are textboxes and combo boxes.

Any help would be appreciated.
 
G

G. Vaught

Main forms /sub forms are created as one form. The Main form always calls
the subform, not the other way around.
Perhaps if you redesign your form, you'll have less headaches.
 
G

Guest

I don't think I was clear with my original email. I am aware that the parent
form calls the subform. However, when I call the parent form from a command
button, the subform is invisible when there is no record in the subform. I
have coded the command button to set the "allow edits", "allow deletions",
and "allow additions" properties on both the parent and subform to false. By
doing this, the subform becomes invisible when there is no record. I hope
this clarifies my problem. I need the subform to remain visible eventhough
there is no data.
 
A

Allen Browne

That's correct. If you open the main form with AllowEdits set to False, then
it subform control does not permit edit either, and then if there are no
records to display in the subform, it goes blank.

The workaround is to set the Locked property of the controls on the main
form to True, instead of setting the AllowEdits to False. This approach
solves another issue also, that AllowEdits blocks any entries in unbound
controls also (which I use heavily for navigation and filtering.)

This article contains code that loops through the bound controls on a form
and locks them:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

The code calls itself recursively so that subforms are also locked. But you
can pass it a list of exceptions, so if you include the name of your subform
control in the exception list, the subform controls will not be locked. (Or
perhaps you do want them locked - just visible - which is the default
behavior of the code.)

To initialize the form so it always comes up locked, call the function in
Form_Load. Alternatively, if you want to be able to open the form locked or
unlocked in different circumstances, you could pass a true/false value in
OpenArgs, and apply it in Form_Load.

HTH
 
G

Guest

It is the "Allow Additions" option that is causing the sub form to not be
visible if there are no records. This is because you are setting the value of
this option to not allow a new record.

If you want it to be visible, only set the "Allow Additions" to false if
there are existing records. Even doing this can be tricky due to the fact
that when you want to allow the user to add a new record you are going to
have to set the value of this option to true again.
 
J

John Vinson

Hello All,

I have a subform that is giving me a headache. Here is my dilema.

The "allow edits", "allow deletions", and "allow additions" properties are
all set to yes on the subform itself. However, when I call the parent form
from a button, the subform becomes invisible. The noted button is coded to
set all the above mentioned properties of the subform to false. The subform
is only invisible when there is no recordsource. However, I would like the
subform to remain visible even when there is no data. The overall form looks
terrible with a huge space due to the invisible subform. The only controls I
have on the subform are textboxes and combo boxes.

Any help would be appreciated.

A Form (whether mainform or subform) will be invisible when a) it is
empty and b) it is not updateable. There is no existing record to
show, and there is no "new" record (because you're not allowing new
records).

Now I agree that it would be nice if it just showed the controls
anyway, but Access just doesn't work that way!

I'd suggest leaving the Allow Additions property True, and writing
code in the BeforeUpdate event to cancel the update if you've opened
the form from the command button.

John W. Vinson[MVP]
 

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