Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Editability of a form with a command button

Status
Not open for further replies.

ehsguy77

IS-IT--Management
Feb 12, 2004
93
US
I think I've been doing things the hard way. To reduce the chance of users typing over information accidentally, I've made three versions of the same form. One has all controls unlocked with data entry set to yes (New records), one has all controls set to locked (view only), and one is set with all controls unlocked with data entry set to No (Editable - called with command button from view only forms).

Is there a way to do this using the same form, by changing some argument in the command button code that calls these this form?
 
Hallo,

If you put the form to be readonly/edited as a subform, you can put a button on the main form to toggle the subforms AllowEdits property.
You can't do it in a single form as setting allowedits to be false means you can't press any buttons either (I don't think)
If you still want to use a single form then you could write a loop to do the hiding, something like:
Code:
dim ctlControl as control
me!btnEdit.setfocus
for each ctlControl in Me.Controls
  if ctlControl.name <>"btnEdit" then ctlControl.Enabled=false
next ctlControl
There's help under 'Each' in Access help.

Hope that helps,

- Frink
 
You can try, when opening the form...

DoCmd.OpenForm "frmForm1", acNormal, , , acFormEdit
DoCmd.OpenForm "frmForm1", acNormal, , , acFormReadOnly
DoCmd.OpenForm "frmForm1", acNormal, , , acFormAdd

or individually, setting the read/write properties, by a method of your choosing. Maybe an option group above the command button?...

Private Sub CmdOpenForm_Click()
Select Case optEditStatus
Case 1
DoCmd.OpenForm "frmForm1"
Forms!frmForm1.AllowAdditions = True
Forms!frmForm1.AllowDeletions = False
Forms!frmForm1.AllowEdits = True
Forms!frmForm1.AllowFilters = False
Case 2
DoCmd.OpenForm "frmForm1"
Forms!frmForm1.AllowAdditions = False
Forms!frmForm1.AllowDeletions = False
Forms!frmForm1.AllowEdits = False
Forms!frmForm1.AllowFilters = False
Case 3....


Hope this helps, Good Luck!
 
There's a bit more info on "control looping" in faq702-5010, too, to build a little on Frink's reply (methods of including/excluding control types etc...)

You could then for instance use buttons on the form, or pass some value as openargs when opening, to invoke different "states" of the form.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top