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

protect a form 1

Status
Not open for further replies.

bronc

Instructor
Aug 28, 2003
145
GB
Hello I'd like to prevent/allow edits and additions to a form by using a toggle button with the code:

Private Sub tglDataEntry_Click()
Dim tf As Boolean

Select Case tglDataEntry.Value
Case True
tglDataEntry.Caption = "All Data"
tf = True
Case False
tglDataEntry.Caption = "Edit Data"
tf = False
End Select

Me.AllowEdits = tf
Me.AllowDeletions = tf
' (do I need a Refresh here)?
End Sub

The only problem is that when when they are toggled off, the form and hence the button is disabled as well.

Can it be done from the form - or do I need to program the ribbon to toggle on and off?
 
Instead of dealing with the Form object, you can just make the form recordset as "snapshot" to make it read-only. Basically, a dynaset recordset is updatable and a snapshot recordset is readonly.

Me.RecordsetType=0 'dynaset
Me.RecordsetType=2 'snapshot

The code also requeries the form and moves the record to the start. So you might need code to move the record to one you want.

Seaport
 
that's amazing in its simplicity. I'd never have thought of that. thanks a lot.
 
i tried and it works fine but how do i return to the record? use a bookmark?
 
Using ADO bookmark is fine. Or you can use code like:

Me.Recordset.FindFirst "PrimaryKeyID=" & ID
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top