Hi,
I found the code below on the net which is just what I'm after for my project. Can anyone modify it so that it works with a form including a subform? Any help appreciated.
Cheers,
millrat
---------------------------------------------
Option Compare Database
Option Explicit
Global Const cTeal As Long = 8421440
Global Const cGrey As Long = 12632256
---------------------------------------------
Function ToggleEdit(frm As Form, bEdit As Boolean)
On Error GoTo err_ToggleEdit
' toggle edit and backcolor
If bEdit Then
With frm
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
.Detail.BackColor = cTeal
End With
Else
With frm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
.Detail.BackColor = cGrey
End With
End If
exit_ToggleEdit:
Exit Function
err_ToggleEdit:
MsgBox "Err Number " & Str(err) & ": " & err.Description
Resume exit_ToggleEdit
End Function
----------------------------------------------
Option Compare Database
Option Explicit
Dim bEdit As Boolean
Dim x As Integer
------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
bEdit = False
x = ToggleEdit(Me, bEdit)
bEdit = Not bEdit
End Sub
---------------------------------------------
Private Sub cmdModify_Click()
On Error GoTo Err_cmdModify_Click
If bEdit Then
cmdModify.Caption = "View All Records"
x = ToggleEdit(Me, bEdit)
'filter records
DoCmd.ApplyFilter , "PK = " & Me!PK
Else
cmdModify.Caption = "Modify Current Record"
x = ToggleEdit(Me, bEdit)
'unfilter records
DoCmd.ShowAllRecords
End If
bEdit = Not bEdit
Exit_cmdModify_Click:
Exit Sub
Err_cmdModify_Click:
MsgBox err.Description
Resume Exit_cmdModify_Click
End Sub
I found the code below on the net which is just what I'm after for my project. Can anyone modify it so that it works with a form including a subform? Any help appreciated.
Cheers,
millrat
---------------------------------------------
Option Compare Database
Option Explicit
Global Const cTeal As Long = 8421440
Global Const cGrey As Long = 12632256
---------------------------------------------
Function ToggleEdit(frm As Form, bEdit As Boolean)
On Error GoTo err_ToggleEdit
' toggle edit and backcolor
If bEdit Then
With frm
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
.Detail.BackColor = cTeal
End With
Else
With frm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
.Detail.BackColor = cGrey
End With
End If
exit_ToggleEdit:
Exit Function
err_ToggleEdit:
MsgBox "Err Number " & Str(err) & ": " & err.Description
Resume exit_ToggleEdit
End Function
----------------------------------------------
Option Compare Database
Option Explicit
Dim bEdit As Boolean
Dim x As Integer
------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
bEdit = False
x = ToggleEdit(Me, bEdit)
bEdit = Not bEdit
End Sub
---------------------------------------------
Private Sub cmdModify_Click()
On Error GoTo Err_cmdModify_Click
If bEdit Then
cmdModify.Caption = "View All Records"
x = ToggleEdit(Me, bEdit)
'filter records
DoCmd.ApplyFilter , "PK = " & Me!PK
Else
cmdModify.Caption = "Modify Current Record"
x = ToggleEdit(Me, bEdit)
'unfilter records
DoCmd.ShowAllRecords
End If
bEdit = Not bEdit
Exit_cmdModify_Click:
Exit Sub
Err_cmdModify_Click:
MsgBox err.Description
Resume Exit_cmdModify_Click
End Sub