B
BBC via AccessMonster.com
I have a sub form that has an Edit/Lock Button to allow/stop the editing of
the records. The Button is on the mainform (code below) and when clicked it
performs as desired to lock/unlock of the subform. I also need to set the
subform (records) to locked when the user moves to another record on the
subform (records should seldom ever be directly changed even on his subform,
thus the edit button). I tried putting the code farther below in the
subforms current event so that any record movements in the subform will
relock the form. The LOCKED property of the subform is not an option for the
form in the current event (intellisense does not show it and I get an error
if I put it there anyway) . The rest of the subforms properties appear to
work.
The Edit/Lock buttons code (located on the main form) Works as expected
including lockingunlocking the subform.
sFranchisedRegSummary is the name of the subform
Private Sub EditRegSummary_Click()
If Me!sFranchiseRegSummary.Locked Then ' is record on subform locked
Me!sFranchiseRegSummary.Locked = False ' open for editing
Me.EditRegSummary.Caption = "Lock" ' show re-lock caption on Button
Else
Me!sFranchiseRegSummary.Form.Dirty = False ' save the existing
record on subform
Me!sFranchiseRegSummary.Locked = True ' lock subform
Me.fSelectRecd.SetFocus ' combobox record selector back on main
form
Me.EditRegSummary.Caption = "Edit" 'reset mainform Edit Button
caption for next record
End If
End Sub
The subforms current event
Private Sub Form_Current() ' current on subform
Me.ID.SetFocus ' set focus to the subform (ex coming from the mainform)
If Me.Dirty Then Me.Dirty = False ' save the subforms record if needed
when record moves
The following line fails to work. I have tried many forms of
this line
Me.Locked=True ' Lock the subform THIS IS WHAT FAILS
other attempts at coding this have been similar to
Me!sFranchiseRegSummary.Form.Locked
Me.sFranchiseRegSummary.Locked
etc.
If Me.Parent!EditRegSummary.Caption = "Lock" Then
On Error Resume Next
Me.Parent!fSelectRecd.SetFocus ' need 2 of these as the first one
occassionally fails
Me.Parent!fSelectRecd.SetFocus ' and I don't know why (yet)
Me.Parent!EditRegSummary.Caption = "Edit"
End If
End Sub
I have temporarly dealt with this issue by putting the following code in the
main forms
fSelectRecd_GotFocus event which happens at the end of the above event
Me!sFranchiseRegSummary.Locked = True
as per
Private Sub fSelectRecd_GotFocus() ' main form's "find a record" combobox
Me!sFranchiseRegSummary.Locked = True ' added as per the locking
problem
If IsNull(Me![ID]) Then DoCmd.GoToRecord , , acLast
' in case no record selected or empty/new record (should
not happen)
End Sub
This seems to work but doesn't seem the "right" way to code it?
Any thoughts on the "proper" way to do this??
the records. The Button is on the mainform (code below) and when clicked it
performs as desired to lock/unlock of the subform. I also need to set the
subform (records) to locked when the user moves to another record on the
subform (records should seldom ever be directly changed even on his subform,
thus the edit button). I tried putting the code farther below in the
subforms current event so that any record movements in the subform will
relock the form. The LOCKED property of the subform is not an option for the
form in the current event (intellisense does not show it and I get an error
if I put it there anyway) . The rest of the subforms properties appear to
work.
The Edit/Lock buttons code (located on the main form) Works as expected
including lockingunlocking the subform.
sFranchisedRegSummary is the name of the subform
Private Sub EditRegSummary_Click()
If Me!sFranchiseRegSummary.Locked Then ' is record on subform locked
Me!sFranchiseRegSummary.Locked = False ' open for editing
Me.EditRegSummary.Caption = "Lock" ' show re-lock caption on Button
Else
Me!sFranchiseRegSummary.Form.Dirty = False ' save the existing
record on subform
Me!sFranchiseRegSummary.Locked = True ' lock subform
Me.fSelectRecd.SetFocus ' combobox record selector back on main
form
Me.EditRegSummary.Caption = "Edit" 'reset mainform Edit Button
caption for next record
End If
End Sub
The subforms current event
Private Sub Form_Current() ' current on subform
Me.ID.SetFocus ' set focus to the subform (ex coming from the mainform)
If Me.Dirty Then Me.Dirty = False ' save the subforms record if needed
when record moves
The following line fails to work. I have tried many forms of
this line
Me.Locked=True ' Lock the subform THIS IS WHAT FAILS
other attempts at coding this have been similar to
Me!sFranchiseRegSummary.Form.Locked
Me.sFranchiseRegSummary.Locked
etc.
If Me.Parent!EditRegSummary.Caption = "Lock" Then
On Error Resume Next
Me.Parent!fSelectRecd.SetFocus ' need 2 of these as the first one
occassionally fails
Me.Parent!fSelectRecd.SetFocus ' and I don't know why (yet)
Me.Parent!EditRegSummary.Caption = "Edit"
End If
End Sub
I have temporarly dealt with this issue by putting the following code in the
main forms
fSelectRecd_GotFocus event which happens at the end of the above event
Me!sFranchiseRegSummary.Locked = True
as per
Private Sub fSelectRecd_GotFocus() ' main form's "find a record" combobox
Me!sFranchiseRegSummary.Locked = True ' added as per the locking
problem
If IsNull(Me![ID]) Then DoCmd.GoToRecord , , acLast
' in case no record selected or empty/new record (should
not happen)
End Sub
This seems to work but doesn't seem the "right" way to code it?
Any thoughts on the "proper" way to do this??