How to stop from changing data

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
 
P

Peter Kaufman

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

Peter
 
G

Guest

Like I said my knowledge is limited.
Can you please expand your answer.

Thanks,
Emilio
 
R

Rick Brandt

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
 
E

Emilio

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


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top