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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggle Edit function to include subform

Status
Not open for further replies.

millrat

Technical User
Dec 23, 2003
98
US
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


 
if what you mean is to Toggle the subform only then instead of
ToggleEdit(Me, bEdit)
use
ToggleEdit(Me.SubformControlName.form, bEdit)

 
pwise
Thanks for the reply.
Actually I want to toggle both the form and the subform.
 
the fastest way to do this is to call ToggleEdit twice
ToggleEdit(Me.SubformControlName.form, bEdit)
ToggleEdit(Me, bEdit)
 
OK thanks for that.
After some inspiration I found that this works too.

ToggleEdit(Me, bEdit) And ToggleEdit(Me.SubformControlName.form, bEdit) And ToggleEdit(etc..)

Thanks for your help
millrat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top