Read Only / Edit Mode button on form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there

I have forms which require users to click a button to be able to edit records. The records are not able to be modified unless the user clicks into edit mode

Problem: I have to use lengthy code to do this. Is there a faster, more efficient way to do this
This is the code is use
Private Sub cmdEditRecords_Click(
On Error GoTo Err_cmdEditRecords_Clic
On Error GoTo Err_cmdEditRecords_Clic
Me.Refres
If cmdEditRecords.Caption = "READ ONLY!" The
Me.AllowAdditions = Tru
Me.AllowDeletions = Tru
Me.AllowEdits = Tru
DoCmd.GoToRecord , , acNewRe
Me.TestLocation.SetFocu

Forms![frmTest]![sfrmTestReading].Form.AllowEdits = Tru
Forms![frmTest]![sfrmTestReading].Form.AllowDeletions = Tru
Forms![frmTest]![sfrmTestReading].Form.AllowAdditions = Tru
Me.cmdNewTree.Enabled = Tru



cmdEditRecords.Caption = "EDIT MODE!
cmdEditRecords.ForeColor = 25
Els
cmdEditRecords.Caption = "READ ONLY!
cmdEditRecords.ForeColor = 1671168
Me.AllowAdditions = Fals
Me.AllowDeletions = Fals
Me.AllowEdits = Fals

Forms![frmTest]![sfrmTestReading].Form.AllowEdits = Fals
Forms![frmTest]![sfrmTestReading].Form.AllowDeletions = Fals
Forms![frmTest]![sfrmTestReading].Form.AllowAdditions = Fals
Me.cmdNewTree.Enabled = Fals


End I
Me.Refres

Exit_cmdEditRecords_Click
Exit Su
Err_cmdEditRecords_Click
If Err.Number = 3314 The
MsgBox "Before you can exit this screen or edit mode, the following fields must contain data: Test Location, Test Date, Indicator Test, Shipment, Variety, Propagatin, Location and Row."
& Chr(13) & Chr(13) & "Make sure all required fields have values."
& Chr(13) & Chr(13) & "To clear the values you have entered, press ESCAPE.
End I
End Su

Regards
Carlee
 
I don't know is my solution is relevant to you.

I found I couldn't enable/disable the form because I have
numerous unbound controls which govern what is being
presented (e.g. What year's data is to show in a subform).
They get disabel along with the bound forms.

Allso, my application makes liberal use of subforms, and
they were problematic.

So, I leave the forms enabled and enable/disable the
fields with this:
Public Sub LockAll(frm As Form, LockStatus As Boolean)

' Lock (or unlock) all controls which are bound to fields.

' while allowing navigational controls to continue to
operate.

Dim ctlTemp As Control
On Error Resume Next
For Each ctlTemp In frm.Controls
If ctlTemp.ControlType = acSubform Then
LockAll ctlTemp.Form, LockStatus
Else
' Ignore field if it has no control source
If HasProperty(ctlTemp, "ControlSource") Then
' and leave it alone if it isn't bound to
a data field
If ctlTemp.ControlSource <> "" _
And Not ctlTemp.ControlSource
Like "=*" _
Then ctlTemp.Locked = LockStatus
End If
End If
Next ctlTemp

End Sub
-----Original Message-----
Hi there,

I have forms which require users to click a button to be
able to edit records. The records are not able to be
modified unless the user clicks into edit mode.
Problem: I have to use lengthy code to do this. Is
there a faster, more efficient way to do this?
This is the code is use:
Private Sub cmdEditRecords_Click()
On Error GoTo Err_cmdEditRecords_Click
On Error GoTo Err_cmdEditRecords_Click
Me.Refresh
If cmdEditRecords.Caption = "READ ONLY!" Then
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
DoCmd.GoToRecord , , acNewRec
Me.TestLocation.SetFocus

Forms![frmTest]!
[sfrmTestReading].Form.AllowEdits = True
Forms![frmTest]!
[sfrmTestReading].Form.AllowDeletions = True
Forms![frmTest]!
[sfrmTestReading].Form.AllowAdditions = True
Me.cmdNewTree.Enabled = True



cmdEditRecords.Caption = "EDIT MODE!"
cmdEditRecords.ForeColor = 255
Else
cmdEditRecords.Caption = "READ ONLY!"
cmdEditRecords.ForeColor = 16711680
Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False

Forms![frmTest]!
[sfrmTestReading].Form.AllowEdits = False
Forms![frmTest]!
[sfrmTestReading].Form.AllowDeletions = False
Forms![frmTest]!
[sfrmTestReading].Form.AllowAdditions = False
Me.cmdNewTree.Enabled = False


End If
Me.Refresh

Exit_cmdEditRecords_Click:
Exit Sub
Err_cmdEditRecords_Click:
If Err.Number = 3314 Then
MsgBox "Before you can exit this screen or edit
mode, the following fields must contain data: Test
Location, Test Date, Indicator Test, Shipment, Variety,
Propagatin, Location and Row." _
 
Back
Top