Open a Form in Read Only or Edit Mode. (1 Viewer)

skelley

Registered User.
Local time
Today, 11:41
Joined
Jul 11, 2000
Messages
69
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

AWF VIP
Local time
Today, 05:41
Joined
Dec 23, 1999
Messages
619
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

Registered User.
Local time
Today, 11:41
Joined
Jul 11, 2000
Messages
69
R. Hicks

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

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:41
Joined
Feb 19, 2002
Messages
43,257
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:41
Joined
Feb 19, 2002
Messages
43,257
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

Registered User.
Local time
Today, 11:41
Joined
Jul 11, 2000
Messages
69
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

Super Moderator
Staff member
Local time
Today, 06:41
Joined
Feb 19, 2002
Messages
43,257
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()
 

rfasantos

New member
Local time
Today, 03:41
Joined
Feb 14, 2014
Messages
1
Open your form with code. Use the Data Mode argument of the DoCmd.Open form method:

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

Replace "YourFormName" with the name of your form.

HTH
RDH

The problem is that when you open a form with this method, you can edit and also add records.

I really like to know how to open with only the edit mode enabled and the add mode desabled.
Is this possible?
 

Users who are viewing this thread

Top Bottom