HI,
I'm trying to write a generic set focus sub/function but am having trouble handling control arrays i.e. option list can anyone see how this can be handled or if this can be actually be done?
This is what I have so far; when I pass in the name of my option array it goes into the case else saying the control name is "object"
VB Code:
Private Sub GenericSetFocus(sCtrlName As String, Optional lStart As Long = 0) On Error GoTo ErrorHandler With Controls(sCtrlName) Select Case TypeName(Controls(sCtrlName)) Case "TextBox" .SelStart = lStart .SelLength = Len(.Text) .SetFocus Case "CheckBox", "CommandButton", "ComboBox" .SetFocus Case "ListBox" ' Need to look into dropping focus back onto specific item in list .SetFocus Case "OptionButton" ' Need to look into index issue here if a control array which it should be ' how to specify item to select by default .SetFocus Case Else MsgBox "This control hasn't been handled yet: " & TypeName(Controls(sCtrlName)) End Select End With Exit Sub ErrorHandler: If Err.Number <> 0 Then MsgBox Err.Number & vbNewLine & _ Err.Description End If End Sub Private Sub cmdValidate_Click() 'GenericSetFocus "txtTesting", 2 'GenericSetFocus "cmdValidate" 'GenericSetFocus "option" GenericSetFocus CStr(Me.optMyOptions(0).Name) 'GenericSetFocus "chk1" 'GenericSetFocus "cbo1" 'GenericSetFocus "lst1" End Sub




Reply With Quote