Using DoCmd.OpenForm method with a mainform 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
 
A

Allen Browne

Open the form normally (not read-only.)

Loop through the controls on the main form, setting their Locked property to
Yes, so they cannot be changed.

Use the Current event of the subform to loop through its controls, and set
Locked to Yes unless Me.NewRecord is true.

For an example of how to loop through the controls of a form, see:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html
Note that the article is doing something different from what you need, but
should serve as a demo of how to determine which controls have a Locked
property to set (e.g. labels and lines do not.)
 
J

John S. Ford, MD

Thank you Allen. That's very helpful!

John
Allen Browne said:
Open the form normally (not read-only.)

Loop through the controls on the main form, setting their Locked property to
Yes, so they cannot be changed.

Use the Current event of the subform to loop through its controls, and set
Locked to Yes unless Me.NewRecord is true.

For an example of how to loop through the controls of a form, see:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html
Note that the article is doing something different from what you need, but
should serve as a demo of how to determine which controls have a Locked
property to set (e.g. labels and lines do not.)
 

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