Eileen Murphy
asked on
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
--------------------------
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
ASKER
Even with a hex value?
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.
ASKER
You may like to look over
https://stackoverflow.com/ questions/ 40588470/s etting-acc ess-colour -codes-in- vba
Gustav also gives a simple solution in the following EE thread, see: https://www.experts-exchan ge.com/Dat abase/MS_A ccess/Q_28 428814.htm l#a4005077 5
https://stackoverflow.com/
Gustav also gives a simple solution in the following EE thread, see: https://www.experts-exchan
ASKER
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"
Same error "Object Required"
ASKER
***STUPID ME!!!! TYPO!!!
If ctrl.ControlType = acTextBox Then
crtl.BackColor
If ctrl.ControlType = acTextBox Then
crtl.BackColor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Maybe use the Is operator ?
Else drag & drop the Ctrl variable in the spy window, and check that it is an expected control (a textBox).
If (ctrl Is Access.TextBox) Then
ctrl.BAckColor = lngColor
End If
Else drag & drop the Ctrl variable in the spy window, and check that it is an expected control (a textBox).
***STUPID ME!!!! TYPO!!!"Option Explicit" is the key.
You should add this at top of all your modules, and it should becomes a reflex.
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!
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!
ASKER
Thanks all! Much appreciated!
Check here