Lock cells with values only

spinkung

Registered User.
Local time
Today, 12:05
Joined
Dec 4, 2006
Messages
267
Hi all,

i have a subform thats set up as...

Stockcode, Qty, length, width, height, weight

...This info comes from a user typing in a stockcode then click add. at that point i look up the stockcode aganist a linked table. If the info is found the i bring back the dimension details and multiply qty and weight.

If the stock code is not found on the linked table then i add the stockcode and quantity and all the dims are set to 0. I then want the user to update the fields manually.

What i'm trying to achieve is locking the fields that have values in so they can't be edited and only allowing the editing of 0 value fileds.

Can this be done?? I've tried a couple of things with me.field.locked = true/false but with no joy.

Many Thanks. Spin.
 
You should be able to do this by using the after update event of the stock code checking for poistive values. or the on current event of the form again checking for valid values.

David
 
solved it with....


Code:
Private Sub length_GotFocus()

If Me.length.Value > 0 Then
    Me.length.Locked = True
Else
    Me.length.Locked = False
End If

End Sub
 
Try something like this (replace FIELDNAME with your field name):

If Me!FIELDNAME > 0 then
Me!FIELDNAME.Enabled = False
Else
Me!FIELDNAME .Enabled = True
End if

And like DCrake said you will need this on the AfterUpdate of the Value field and OnCurrent of the form

Regards
 
Also I am not sure whether Length is a reserved word in Access.
 
** updated

I've now got it down to this with a function.

crake and james - i couldn't do it on the after update event because by that time the user has already made changes??

Code:
Private Sub txt_weight_GotFocus()
'call the lock field function
    lock_field Me.txt_weight
End Sub
Public Function lock_field(fname As TextBox)
'lock text box based on value
    If fname.Value > 0 Then
        fname.Locked = True
    Else
        fname.Locked = False
    End If
End Function
 

Users who are viewing this thread

Back
Top Bottom