make the form protect all records unless newest 8 records

samm

Registered User.
Local time
Today, 18:13
Joined
Sep 19, 2003
Messages
27
Hi dears

Can I make the form protect all records unless newest 8 records
 
You'll need some way of identifying the 8 newest records. I've never tried this, so I here's my first thought:
- Your table/query will need some way of knowing which records are newest. A date/time field would work.
- How to id the newest 8? You can use a top values query to find that. Save the query so you can call it repeatedly.
- You can then use the form's Current event to set the user's ability to edit records based on whether the current record is one of the top 8. Use a DCount function to test whether or not the current record's date/time field is one of the top 8. Something like:
Code:
If DCount("DateTime","qryTop8","DateTime=" & Me.[txtDateTime]))>0 Then
    Me.AllowAdditions = False
    Me.AllowDeletions = False
    Me.AllowEdits = False
Else
    Me.AllowAdditions = True
    Me.AllowDeletions = True
    Me.AllowEdits = True
End If
I'm sure this code will run quite slowly, unfortunately. And it won't be very effective in a multiuser environment.
 
I would cheat with subforms. Select the top 8 as dcx693 suggests and show these in a subform in edit mode. Select the rest and show these in a subform that is read only.
 
I use this code but I have error 0n line 1 and 10 with yellow and and red color.




Private Sub Form_Current()
Me.RecordsetClone.MoveLast
If Me.CurrentRecord <= Me.RecordsetClone.RecordCount - 8 Then
Me.AllowEdits = False
' Me!YourS.Form.AllowEdits = False
Else
Me.AllowEdits = True
' Me!YourSubForm.Form.AllowEdits = True
End If

If DCount("DateTime","qdate","DateTime=" & Me.[datetxt]))>0 Then

Me.AllowAdditions = False
Me.AllowDeletions = False
Me.AllowEdits = False
Else
Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True
End If
End Sub


qdate = query with this criteria :
Between [Forms]![Fmain1]![from] And [Forms]![Fmain1]![to]
 

Users who are viewing this thread

Back
Top Bottom