Don't Allow Editing if a field is populated

G

Guest

I am trying to lcok the record from being edited if one field is populated.
To make it a little more involved I want to be able to edit only that one
field. For example if the date_closed field has a date in it the record
should not be editable except for the ability to remove the date_closed value
which would then open the record for editing. Here is what I tried for the
basic portion but it does not seem to work. Any help would be greatly
appreciated.

Private Sub date_closed_AfterUpdate()
If IsNull(date_closed) Then
Form.AllowEdits = True
Else
Form.AllowEdits = False
End If
End Sub
 
R

Rick B

First, you need to have this procedure run in the event you specified and
ALSO in the "current" event. That way the field will be checked as you page
from one record to another.

Second, you are setting the form's allow edits. You specifically told us
you want to lock all the controls except one. Don't lock the record, lock
the controls.

Me.SomeControlName.Locked = True
Me.SomeOtherControlName.Locked = True
etc.
Else
Me.SomeControlName.Locked = False
Me.SomeOtherControlName.Locked = False
etc.
 
R

Rob

Steve

If I am understanding you correctly, you want the [date_closed] field to be
locked from editing if its populated, but have the ability to clear its
contents, if needed.

You are on the right track with the code below. I would probably
short-circuit the code like this:

Private Sub date_closed_AfterUpdate()
Form.AllowEdits = IsNull(date_closed)
End Sub

IsNull is a boolean value. The .AllowEdits expects a boolean value. Enough
said....

To have the ability to clear the contents and make the field available to
edit again, you will need to include a command button.

When the .AllowEdits = False, then make the command button visible. When the
user clicks on the command button, then you can set the field
..AllowEdits=True and clear the contents of the field.

HTH

Rob

--
FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com

FMS Advanced Systems Group
http://www.fmsasg.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