GSD4ME
asked on
TypeOf and control selecting not working
Q: Why doesn't this work for the checkbox?
with MyForm
call myproc (.anyComboBox)
call myproc (.anytextBox)
call myproc (.anyCheckBox)
etc.
sub myProc (p_Control as Control)
if (typeOf p_Control is ComboBox) then
...
end if
if (typeof p_Control is checkbox) then
...
endif
if (typeof p_Control is textbox) then
...
endif
end sub
The ".. is combobox" is the only block that is entered and all the other tests give false.
Anyone any suggestions?
with MyForm
call myproc (.anyComboBox)
call myproc (.anytextBox)
call myproc (.anyCheckBox)
etc.
sub myProc (p_Control as Control)
if (typeOf p_Control is ComboBox) then
...
end if
if (typeof p_Control is checkbox) then
...
endif
if (typeof p_Control is textbox) then
...
endif
end sub
The ".. is combobox" is the only block that is entered and all the other tests give false.
Anyone any suggestions?
Try this experiment:
Private Sub Form_Load()
Dim curControl As Control
For Each curControl In Me.Controls
myProc curControl
Next curControl
End Sub
Sub myProc(p_Control As Control)
If (TypeOf p_Control Is ComboBox) Then
Debug.Print "Combox Detected"
End If
If (TypeOf p_Control Is CheckBox) Then
Debug.Print "CheckBox Detected"
End If
If (TypeOf p_Control Is TextBox) Then
Debug.Print "TextBox Detected"
End If
End Sub
Private Sub Form_Load()
Dim curControl As Control
For Each curControl In Me.Controls
myProc curControl
Next curControl
End Sub
Sub myProc(p_Control As Control)
If (TypeOf p_Control Is ComboBox) Then
Debug.Print "Combox Detected"
End If
If (TypeOf p_Control Is CheckBox) Then
Debug.Print "CheckBox Detected"
End If
If (TypeOf p_Control Is TextBox) Then
Debug.Print "TextBox Detected"
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the very quick response - it was an urgent request.
AlexFm and IdleMind - many thanks for your efforts.
IdleMind - it didn't cure the problem either - I only got ComboBox coming up.
AlexFm and IdleMind - many thanks for your efforts.
IdleMind - it didn't cure the problem either - I only got ComboBox coming up.
How odd... worked great on my system. Wonder what was going on?...
Anyway, glad you were able to find a solution that worked for you.
Idle_Mind
Anyway, glad you were able to find a solution that worked for you.
Idle_Mind
Private Sub Command1_Click()
myProc Combo1
End Sub
Private Sub Command2_Click()
myProc Text1
End Sub
Private Sub Command3_Click()
myProc Check1
End Sub
Sub myProc(p_Control As Control)
If (TypeOf p_Control Is ComboBox) Then
MsgBox "Combo"
End If
If (TypeOf p_Control Is CheckBox) Then
MsgBox "Checkbox"
End If
If (TypeOf p_Control Is TextBox) Then
MsgBox "Textbox"
End If
End Sub