I've got two subs: cmdSafe and checkTime. I want to call subCheck and pass a userform control.
Private Sub cmdSafe_click()
Call checkTime(ufTimes.txtBegin)
End Sub
Sub checkTime(cntrl as Control)
'Do something
End sub
In this case, I'm getting an error when it tries to call the sub. Run-time error 424: Object required.
I went to check ufTimes.txtBegin, but this gives the value of the textbox, 15
.
I hoped to be able to solve this by changing the first sub to the following:
Private Sub cmdSafe_click()
Dim ctl as control
ctl = ufTimes.txtBegin
Call checkTime(ufTimes.txtBegin)
End Sub
This gave me another error (Run-time error 91: Object variable or With block not set
) on the line ctl=ufTimes.txtBegin
, probably because it's trying to set ctl to be a value. How do I solve this? I want to pass a control through, and it should also be able to be a ComboBox for example
ctl = ufTimes.txtBegin
is interpreted ascontrol = "15"
– GrafitufTimes
yourUserForm
or yourTextBox
? It's theUserForm
, right? What version of Excel? – cxwSet ctl = ufTimes.txtBegin
. – FadiCall CheckTwoNumbers(ufTimes.Controls("cntrl"))
. – Fadi