Using DoCmd.OpenForm with form AND subform

J

John S. Ford, MD

I'm using DoCmd.OpenForm to open a mainform and its subform using a WHERE
statement from a command button on another form:

DoCmd.OpenForm "frmMainForm", , , WHERE statement, acFormReadOnly

I want the user to only to be to read the record in the mainform without
editing or adding a new record.

However, I want the SUBform to be in acFormAdd that is I want my user to be
able to read the previous records in the subform using the navigation
buttons and be able to add new records.

How can the datamode argument of the OpenForm method be different for the
Mainform and the subform?

John



--
-------------------------------------------------------
John S. Ford, MD, MPH
Assistant Professor of Medicine
David Geffen School of Medicine at UCLA
Harbor-UCLA Medical Center
(e-mail address removed)
http://califmedicineman.blogspot.com
 
K

K Dales

You don't necessarily need two OpenForm methods. You can set all the
controls on the main form to be disabled (enabled=False) and locked to
prevent entry or editing.
 
J

John S. Ford, MD

Dear K,

That sounds like a good idea. You mean simply open the form as acFormAdd
but lock out the controls and nav buttons on the mainform? Will the subform
then be "addable" but prior records readable and not editable?

John
 
K

K Dales

You will need to control it all through code. You could keep the controls on
the subform locked until the user chooses to add a new record, then use the
BeforeUpdate event to detect when the record is saved to relock the controls.

This could get cumbersome, depending on the number of controls on the main
form and subform, but I don't know how else to have different read/write/edit
capabilities on a subform than on the main form.

You may want to consider two separate but "synched" forms instead. Instead
of the subform have the same "sub" data set displayed on a separate form
side-by-side with the main form, using code to keep the data on the two in
synch. Then you can easily open them in different read/write modes.
 

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