How to stop from changing data

  • Thread starter Thread starter Emilio
  • Start date Start date
E

Emilio

When a form is open I want to stop the user from making
changes if date is more than 15 days.
I tried many things like below but my knowledge is
limited.

Private Sub Status_BeforeUpdate(Cancel As Integer)

If IsLoaded("ScheduleSubformFriday") And Me!JobDate < (Now
() -15) Then

Cancel = True

Else
DoCmd.Beep
End If
End Sub


Many thanks,
Emilio
 
Can you handle an unbound form? It's really the best way to handle
anything but the most basic validation.

Peter
 
Emilio said:
When a form is open I want to stop the user from making
changes if date is more than 15 days.
I tried many things like below but my knowledge is
limited.

Private Sub Status_BeforeUpdate(Cancel As Integer)

If IsLoaded("ScheduleSubformFriday") And Me!JobDate < (Now
() -15) Then

Cancel = True

Else
DoCmd.Beep
End If
End Sub

In the Form's Current Event you can use code similar to...

If Me!JobDate < Date()-15 Then
AllowEdits = False
Else
AllowEdits = True
End If

The only problem with AllowEdits is that is dis-allows ALL editing on the
form, even unbound controls. If you have any unbound controls that you
still want the user to be able to change then you can't use AllowEdits. In
those cases I do the following...

In Design View select all controls bound to data and give them all a common
Tag property like "Lock". Then in the Form's Current event...

Dim cnt as Control

For Each cnt in Me
If Me!JobDate < Date()-15 Then
If cnt.Tag = "Lock" Then cnt.Locked= True
Else
If cnt.Tag = "Lock" Then cnt.Locked= False
End If
Next Cnt
 
Perfect

Thanks a lot,
Emilio



-----Original Message-----


In the Form's Current Event you can use code similar to...

If Me!JobDate < Date()-15 Then
AllowEdits = False
Else
AllowEdits = True
End If

The only problem with AllowEdits is that is dis-allows ALL editing on the
form, even unbound controls. If you have any unbound controls that you
still want the user to be able to change then you can't use AllowEdits. In
those cases I do the following...

In Design View select all controls bound to data and give them all a common
Tag property like "Lock". Then in the Form's Current event...

Dim cnt as Control

For Each cnt in Me
If Me!JobDate < Date()-15 Then
If cnt.Tag = "Lock" Then cnt.Locked= True
Else
If cnt.Tag = "Lock" Then cnt.Locked= False
End If
Next Cnt


--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


.
 
Back
Top