Runtime Error 424 Object Required

D

default105

Access 2000, WinXP

Thanks in advance!
I have a form that pops up for a user to click on a button to input a number
into a form. I would like to add a conditional format to color the button
red if there is a value already in the textbox. I do not have any problem
doing this if I type in the name of the control in the function call, however
if I am trying to dynamically create it, it fails every time. Here is where
I am at so far (which I know is wrong), can anyone please tell me how to do
this?

Private Sub Form_Load()
Dim strBtn As String

Dim ctlBtn As Object

strBtn = "Me.Command" & Forms!frmOrders.txtPriority


Set ctlBtn = strBtn
Dim lngBool As Boolean
Dim lngBackColor As Long
' Call the Color Picker Dialog
' lngBackColor = aCmdDialogColor()
' If error set ForeColor to Black

' Pass the Selected Color to the function
Debug.Print lngBackColor
'lngBool = fCmdButTextPic(Me.Command0, lngBackColor)
lngBool = fCmdButTextPic(ctlBtn, 8388863)
Set ctlBtn = Nothing
End Sub
 
D

Dirk Goldgar

default105 said:
Access 2000, WinXP

Thanks in advance!
I have a form that pops up for a user to click on a button to input a
number
into a form. I would like to add a conditional format to color the button
red if there is a value already in the textbox. I do not have any problem
doing this if I type in the name of the control in the function call,
however
if I am trying to dynamically create it, it fails every time. Here is
where
I am at so far (which I know is wrong), can anyone please tell me how to
do
this?

Private Sub Form_Load()
Dim strBtn As String

Dim ctlBtn As Object

strBtn = "Me.Command" & Forms!frmOrders.txtPriority


Set ctlBtn = strBtn

Try this:

strBtn = "Command" & Forms!frmOrders.txtPriority

Set ctlBtn = Me.Controls(strBtn)
 
D

default105

Thanks DG,

I was on that path but instead I tried Forms(me).Controls(strBtn) but was
getting syntax error. I never thought of using just controls only. Thanks
much, it works perfectly.
--
Pete Blackburn - words to live by:
"Don''t ever let somebody tell you. You can''t do something.You got a
dream,You gotta protect it." Edited Quote from the Pursuit Of Happiness
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top