Lock Field after update

kobiashi

Registered User.
Local time
Today, 04:53
Joined
May 11, 2018
Messages
258
hi

i want to be able to lock a field on a form after the user updates it, i have an if statement but i cant seem to get it to work, can someone take a look at it and tell me if theres something missing from it

Code:
Private Sub Form_Current()
    If IsNull(Me.cboVehicleID) Then
        cboVehicleID.Locked = False
    Else
        cboVehicleID.Locked = True
        Me.cboVehicleID.BackColor = RGB(206, 206, 206)
    End If
End Sub
 
Shouldn't you be using the Me. prefix everywhere?
 
i tried that, but didnt have any effect
 
Perhaps you have a zero length string
Use

Code:
If Nz(Me.cboVehicleID,"")="" Then

If for any reason that also fails, try setting the control as locked by default then in form current unlock if the field is null or a ZLS
 
you can also simplify your code


cboVehicleID.Locked =nz(Me.cboVehicleID,"")<>""

I'm assuming cboVehicleID is text and not a number

i want to be able to lock a field on a form after the user updates it
You are using the form current event - so the code won't fire until you return to the record - not sure if that is what you mean or you mean the user only has one chance to choose the right ID, in which case you need to use the cboVehicleID control after update event as well
 
use the control's OnGotFocus Event instead of the Form's Current event:

Private Sub cboVehicleID_GotFocus()
Me.cboVehicleID.Locked = (Trim(Me.cboVehicleID & "")="")
End Sub
 
Or the LostFocus event. But whichever one you choose, use the same event for each control subject to this restriction. I.e. don't use GotFocus sometimes and LostFocus sometimes.

The issue also might be not that you use GotFocus or LostFocus instead of Current, but rather IN SUPPLEMENT to Current. This would apply if it is possible for the field to be occupied when you navigate to a different record because was already updated. If that can happen, then both Current and one of the Focus events will be needed to keep it "clean."
 
thanks everybody for the help in sorting this, the only one i could get to work was

Code:
Private Sub cboVehicleID_GotFocus()
    Me.cboVehicleID.Locked = Nz(Me.cboVehicleID, "") <> ""
End Sub
 

Users who are viewing this thread

Back
Top Bottom