View Full Version : Open a Form in Read Only or Edit Mode.


skelley
08-17-2000, 11:19 AM
Is there a way to have one (1) form open in either read only mode or edit mode? For the moment I have two (2) forms. One with the properties set to read only and the other not. Every time I make a change to one, I have to recreate the other by copying the first and changing the properties.

R. Hicks
08-17-2000, 11:37 AM
Open your form with code. Use the Data Mode argument of the DoCmd.Open form method:

This opens form in Add Mode:
DoCmd.OpenForm "YourFormName", , , , acFormAdd

This opens form in Read Only Mode:
DoCmd.OpenForm "YourFormName", , , , acFormReadOnly

This opens form in Edit Mode:
DoCmd.OpenForm "YourFormName", , , , acFormEdit

Replace "YourFormName" with the name of your form.

HTH
RDH

skelley
08-17-2000, 11:50 AM
R. Hicks

Thx for response. I am using an Access Switchboard. Where do I put this code to work?

Pat Hartman
08-17-2000, 12:45 PM
Unfortunately the switchboard only gives you the option of opening in edit view or add view. What I do to get around this is to write a public function that contains only the following line of code:

DoCmd.OpenForm "MyFormName", , , , acFormReadOnly

Then instead of selecting "open form in edit mode" from the switchboard manager, I choose "run code" and specify the appropriate function.

skelley
08-17-2000, 01:00 PM
What is a "public function"?

Pat Hartman
08-17-2000, 07:14 PM
A function you write in a code module that is declared as public. The public declaration makes it available to any object in the entire database. Private functions are only available within the module in which they are defined.

Public Function YourFunction()
DoCmd.OpenForm "YourFormName", , , , acFormReadOnly
End Function

skelley
08-18-2000, 09:39 AM
The above did not work from an Access Switchboard or I do not know how to code the "appropriate function" into the switchboard.

Please advise.

Pat Hartman
08-21-2000, 03:22 PM
Choose the Run Code command and when you type your function name in the Function name box, follow it with open and close parens:

YourFunction()