Frequently Asked Questions

 

1.

How to move the focus to a specific control on launch

 

1.

How to move the focus to a specific control on launch


The easiest way is to make the control the first control (that can receive the focus) that you create (the taborder is set to the same order in which the controls are created).
This method works for both simple forms and callback forms

Another way is to use the SetFocus method of the control in the eventhandler.
Because you can only use SetFocus when a form is visible (AFTER the Show method),
the best way is to set the focus in the *ACTIVATE event as in the example below.

To enable the eventhandler you need to pass the eventhandler prefix when creating the WshDialog.Kit object : Set oDlg = Wscript.CreateObject("WshDialog.Kit", "oDlg_")
Also, you must enable callback functionality for the form : oFrm.CallBack=True

Sub oDlg_ClickHandler(sForm, sControl)

    Dim oFrm, oCtl

    Set oFrm = oDlg.Frm(sForm)
    Set oCtl = oFrm.Ctl(sControl)

    Select Case sForm
    Case "<The name of your form (may be empty)>"
        Select Case sControl
        Case "*ACTIVATE"
            oFrm.Ctl("<The name of a control>").SetFocus
        Case "<Other events/controls>"
        Case "*CLOSE"
            oFrm.Hide
        Case Else
        End Select
    Case Else
    End Select

End Sub