Lock field for a record if another field is null

amclfc

Registered User.
Local time
Today, 00:10
Joined
Oct 14, 2004
Messages
13
Lock field for a record if another field is null:

I would like to stop users from entering a date in "Ctrl Closed" unless they have populated "Ctrl Reason" for any given record.

Not sure how to do this.

Any ideas would be greatly appreciated.
 
The only way I can think you would do this is to use VBA. It would be pretty simple.

1. Make the field Ctrl Closed "Locked".

2. On the "BeforeUpdate" event of the Ctrl Reason, add your code to ensure there is a value in Ctrl Reason, and then unlock Ctrl Closed.

3. You will need to lock the Crtl Closed again when the record changes, so use the "On Current" event of your form.

This should be OK on a single record form, it may be OK on a continuous form as well. My "Events" knowledge is no great, but I think the above events are OK. If not, I am sure one of our local gurus will spot it and post the correct event.
 
?

Thanks, this works:

Private Sub Ctrl_Check_GotFocus()
If Me.Ctrl_Res = "CS10" Then
Me.Ctrl_Check.Locked = True
Else
Me.Ctrl_Check.Locked = False

End If

End Sub

But when I try it for Null values like so I get a runtime 424 error "Object required", any help please?:

Private Sub Ctrl_Check_GotFocus()
If Me.Ctrl_Res Is Null Then
Me.Ctrl_Check.Locked = True
Else
Me.Ctrl_Check.Locked = False

End If

End Sub
 
amclfc said:
Private Sub Ctrl_Check_GotFocus()
If Me.Ctrl_Res Is Null Then
Me.Ctrl_Check.Locked = True
Else
Me.Ctrl_Check.Locked = False
End If
End Sub

Try

Code:
If Me.Ctrl_Res = "" Then

Unless you actually have "Null" values in this field, then "Is Null" won't pick them up.
 
This will check if the field is Null or an empty string...

Code:
Private Sub Ctrl_Check_GotFocus()

If IsNull(Ctrl_Res) Or Ctrl_Res = "" Then
     Me.Ctrl_Check.Locked = True
Else
     Me.Ctrl_Check.Locked = False
End If

End Sub
 
Works A Treat

Thanks to all your input I've got it working like a treat. Super people. :D
 

Users who are viewing this thread

Back
Top Bottom