How to prevent User against Editing on Main Form & its subform

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to Prevent User from Editing any changes on the record of Main form or
Subform if the below criteria meets :

If Date - Me.FormDt > 10 Then
'...dont let user to any changes on the record, show msg
End If

Main Form name is "AttdnFormA"
SubForm Name is "AttdnFormB"

Request to advise the codes in details, so that I can complete this job.
Because, it is very important data, the changes can be valid till 10 days, if
it 10 days expires, it will allow user to view or print but should allow user
to make any changes.

I tried the follwing code, the idea from help file, but failed :

Private Sub Form_Dirty(Cancel As Integer)
Dim ctlC As Control
If Date - Me.FormDt >10 Then
For Each ctlC In Me.Controls
ctlC.Value = ctlC.OldValue
Next ctlC
End If
End Sub

Please advise.

Regards.
 
Hi, to use the Dirty event, set the Cancel argument to true if user
shouldn't edit record.

Private Sub Form_Dirty(Cancel As Integer)
If DateDif("d", Me.FormDt, Date)> 10 Then
Msgbox "Can't edit record since it's more than 10 days old"
Cancel= True
End If
End Sub

HTH, Graeme.
 
Irshad said:
I want to Prevent User from Editing any changes on the record of Main form or
Subform if the below criteria meets :

If Date - Me.FormDt > 10 Then
'...dont let user to any changes on the record, show msg
End If

Main Form name is "AttdnFormA"
SubForm Name is "AttdnFormB"

Request to advise the codes in details, so that I can complete this job.
Because, it is very important data, the changes can be valid till 10 days, if
it 10 days expires, it will allow user to view or print but should allow user
to make any changes.


Try using the AllowEdits property.

In the form's Current event procedure:

If DateDiff("d", Me.FormDt. Date) > 10 Then
Me.AllowEdits = False
Me.AllowDeletions = False
Me.AttdnFormB.Form.AllowEdits = False
Me.AttdnFormB.Form.AllowDeletions = False
Else
Me.AllowEdits = True
Me.AllowDeletions = True
Me.AttdnFormB.Form.AllowEdits = True
Me.AttdnFormB.Form.AllowDeletions = True
End If
 
Back
Top