mrwendell
Very astute. There are two issues with the above solution...
- It disables "edits" for all records retrieved
- Any unbound combo or list boxes or toggle boxes used for searching will fail to work becuase the values for these controls will also be read-only.
My approach is to add a toggle box which is interpretted as True/False. You can also use a boolean "flag" on the records to prevent further editing.
Once you have decided on how to prevent editing / allowing editing, there are two parts to the "trick"...
- Use OnCurrent event procedure
- You code will lock / unlock the controls you want to affect.
Assumption:
tglNoEdit - toggle button on form
Frozen - field on table to freeze a record
Code:
[COLOR=blue]
Private Sub Form_Current()
[/color]
SetScreen
End Sub
[COLOR=blue]
Private Sub tglNoEdit_AfterUpdate()
[/color]
Me.tglNoEdit = Not Me.tglNoEdit
SetScreen
End Sub
[COLOR=blue]
Private Sub SetScreen()
[/color]
Dim booSetScreen As Boolean
If Me.frozen Then
Me.tglNoEdit = True
End If
booSetScreen = Me.tglNoEdit
Me.TextBox02.Locked = booSetScreen
Me.Combobox04.Locked = booSetScreen
Me.ListBox06.Locked = booSetScreen
Me.textBox08.Locked = booSetScreen
Me.SubForm1.Locked = booSetScreen
Me.SubForm2.Locked = booSetScreen
Me.TextBox10.Visible = Not booSetScreen
If booSetScreen Then
Me.EditRecord.Caption = "View" & vbCrLf & "Only"
Me.EditRecord.ForeColor = vbBlue
SetUser
Else
Me.EditRecord.Caption = "Edit" & vbCrLf & "Record"
Me.EditRecord.ForeColor = vbRed
End If
End Sub
...So what happens here.
- The SetScreen subrouting locks / unlocks various controls (text boxes, combo boxes, list boxes) and subforms.
- Two conditions can affect the lock / unlock condition. A) the record is "frozen", the control on the form are always set to Locked; B) By toggleing the toggle button.
- Other controls are always left unlocked such as unbound controls (combo boxes for searching for a record or applying filters)
- The SetScreen also changes the caption on the toggle box so the user can visually see the "edit" status.
- The OnCurrent event always checks the current record for the forzen / unfrozen status.
Richard