Results 1 to 11 of 11

Thread: Generic Setfocus [Resolved]

Threaded View

  1. #1

    Thread Starter
    Fanatic Member aconybeare's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    772

    Resolved Generic Setfocus [Resolved]

    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:
    1. Private Sub GenericSetFocus(sCtrlName As String, Optional lStart As Long = 0)
    2.     On Error GoTo ErrorHandler
    3.     With Controls(sCtrlName)
    4.     Select Case TypeName(Controls(sCtrlName))
    5.         Case "TextBox"
    6.             .SelStart = lStart
    7.             .SelLength = Len(.Text)
    8.             .SetFocus
    9.        
    10.         Case "CheckBox", "CommandButton", "ComboBox"
    11.             .SetFocus
    12.        
    13.         Case "ListBox"
    14.             ' Need to look into dropping focus back onto specific item in list
    15.             .SetFocus
    16.            
    17.         Case "OptionButton"
    18.             ' Need to look into index issue here if a control array which it should be
    19.             ' how to specify item to select by default
    20.             .SetFocus
    21.            
    22.         Case Else
    23.             MsgBox "This control hasn't been handled yet: " & TypeName(Controls(sCtrlName))
    24.     End Select
    25.     End With
    26. Exit Sub
    27. ErrorHandler:
    28.     If Err.Number <> 0 Then
    29.         MsgBox Err.Number & vbNewLine & _
    30.                 Err.Description
    31.     End If
    32. End Sub
    33.  
    34. Private Sub cmdValidate_Click()
    35.  
    36.     'GenericSetFocus "txtTesting", 2
    37.     'GenericSetFocus "cmdValidate"
    38.     'GenericSetFocus "option"
    39.     GenericSetFocus CStr(Me.optMyOptions(0).Name)
    40.     'GenericSetFocus "chk1"
    41.     'GenericSetFocus "cbo1"
    42.     'GenericSetFocus "lst1"
    43. End Sub
    Last edited by aconybeare; Jul 1st, 2005 at 03:25 AM. Reason: Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width