VBA Run-time Error 424 Object Require

VBA Object Required Error: Not sure why this isn't working. I've used this code in the past.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Form_Current()

    If Me.NewRecord Then Exit Sub
   
    Me.CursorHold.SetFocus
   
    If Me.SelYear = "ALL" Then
        Call LockUnlockForm(True, "#D5D5D5")
        Me.lblLock.Visible = True
    Else
        Call LockUnlockForm(False, "#FFFFFF")
        Me.lblLock.Visible = False
    End If
   
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Function LockUnlockForm(ynEnabled As Boolean, strColor As String)

    If IsNull(Me.ProjectName) Then Exit Function
   
    Dim ctrl As Control
     
    For Each ctrl In Me.Controls
        If ctrl.Tag = "LockUnlock" Then
     
            If ctrl.ControlType = acTextBox Then
                crtl.BackColor = strColor <<<<<<<<<<<<<<<<<<<<< Run-time Error 424 Object Required
            End If
            ctrl.Locked = ynEnabled
        End If
    Next

End Function
Eileen MurphyIndependent Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
BackColor value is Long
Check here
Eileen MurphyIndependent Application DeveloperAuthor Commented:
Even with a hex value?
Fabrice LambertConsultingCommented:
Even with a hex value?
Yep, an hexadecimal value is just a different representation of a number (base 16) than you usually see (base 10).
I suggest that you use the RGB() function when working with color, it is more readable and have more meaning than a pure number.
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Eileen MurphyIndependent Application DeveloperAuthor Commented:
Screen Shot
Tried with long....

If Me.SelYear = "ALL" Then
        Call LockUnlockForm(True, RGB(213, 213, 213))
        Me.lblLock.Visible = True
    Else
        Call LockUnlockForm(False, RGB(255, 255, 255))
        Me.lblLock.Visible = False
    End If
Daniel PineaultPresident / Owner CARDA Consultants Inc.Commented:
Eileen MurphyIndependent Application DeveloperAuthor Commented:
Thank you but it still bothers me.... the value on the long "color" is 14043909 and it is a text box - I have used this code before - in fact I copied it -- as I often do -- and it's got to be something stupid I'm missing...

Same error "Object Required"
Eileen MurphyIndependent Application DeveloperAuthor Commented:
***STUPID ME!!!! TYPO!!!

If ctrl.ControlType = acTextBox Then
                crtl.BackColor
Eileen MurphyIndependent Application DeveloperAuthor Commented:
Typo!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fabrice LambertConsultingCommented:
Maybe use the Is operator ?
If (ctrl Is Access.TextBox) Then
    ctrl.BAckColor = lngColor
End If

Open in new window


Else drag & drop the Ctrl variable in the spy window, and check that it is an expected control (a textBox).
Fabrice LambertConsultingCommented:
***STUPID ME!!!! TYPO!!!
"Option Explicit" is the key.
You should add this at top of all your modules, and it should becomes a reflex.
Daniel PineaultPresident / Owner CARDA Consultants Inc.Commented:
Glad you got it all sorted out!


Also, Fabrice is very right.  Try to remember to always add Option Explicit whenever you create a new module, it will save you many headaches in the long run!
Eileen MurphyIndependent Application DeveloperAuthor Commented:
Thanks all! Much appreciated!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.