Lock a field after user input

rplohocky

Registered User.
Local time
Today, 12:40
Joined
Apr 13, 2017
Messages
45
I have found a ton of requests for this issue online but none of them seem to work.

I am simply trying to lock a field after the user inputs a date into a field on my form. Below is some code I found from another thread from years ago that seemed to work for the person that requested it but its not working for me.

Can anyone see any errors in this code? The first part works fine but the second part turns red when I'm in VBA. It highlights "Overall" specifically.

Any help would be greatly appreciated Thank you!

Code:
Private Sub Form_Current()
    If Nz(Me![Deployment Date], "") = "" Then
        Me!archivehotelsmacro.Visible = False
    Else
        Me!archivehotelsmacro.Visible = True
    End If

'******BELOW THIS AREA DOESN'T WORK*********

Dim bolBaselineDate As Boolean

bolBaselineDate = IIf(Nz(Me![Old Overall Rank Postion], "") = "", False, True)

If bolBaselineDate = True Then
Me.Combo565.SetFocus
Me!Old Overall Rank Postion.Enabled = False
Me!Old Overall Rank Postion.Locked = True
Else
Me!Old Overall Rank Postion.Enabled = True
Me!Old Overall Rank Postion.Locked = False
End If
   End Sub
 
Three main things wrong.

1. You need [] around the items in the last section as they contain spaces.
2. If a control is disabled it doesn't need to be locked as well
3. Replace all Me! with Me. throughout your code

Hopefully that will fix it for you
 
further to ridders comments, you can't change the enabled/locked properties when the control has focus.

You also don't need all that code. All you need is

[Old Overall Rank Postion].Enabled=not isnull([Old Overall Rank Postion])

note that using the form current event is only triggered when the record is selected so will not work until the user leaves the record and then returns
 

Users who are viewing this thread

Back
Top Bottom