Refer to combox from activecontrol name

B

BigPig

Hi All,

In a userform with rows of comboboxes and textboxes, after exiting a
textbox, if there is nothing in it, and there is nothing in a combobox to
it's immediate left then "nothing", else do "this".

What I'm trying to do is with the ActiveControl name, I can ID the cbx to
the left, then check the cbx's value, and do this or that.

This is what I wrote, but I'm stumped.

With frm_tech_lv
Dim NameOfActiveControl As String
NameOfActiveControl = ActiveControl.Name
Dim CbxLvCtrlNm As String
CbxLvCtrlNm = "frm_tech_lv.cbx_tpl_" & Mid(NameOfActiveControl, 9,
4) & "_lc" & Right(NameOfActiveControl, 1)
Dim cbx As ComboBox
Set cbx.Name = CbxLvCtrlNm

If ActiveControl.Value = "" And cbx = "" Then
Else
MsgBox "From time needed."
Exit Sub
End If
End With

Any and all suggestions would be greatly appreciated. Thanks.
 
D

Dave Peterson

Maybe

With frm_tech_lv
Dim NameOfActiveControl As String
Dim CbxLvCtrlNm As String
Dim cbx As Control

NameOfActiveControl = ActiveControl.Name
CbxLvCtrlNm = "frm_tech_lv.cbx_tpl_" & Mid(NameOfActiveControl, 9, 4) _
& "_lc" & Right(NameOfActiveControl, 1)

Set cbx = me.controls(CbxLvCtrlNm)

If ActiveControl.Value = "" And cbx.value = "" Then
Else
MsgBox "From time needed."
Exit Sub
End If
End With
 

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