Code:
Private Sub Command1_Click()
  If Check2 = 0 Then
    
    
    ' Set CancelError is True
    CommonDialog1.CancelError = True
    On Error GoTo ErrHandler
    ' Set flags
    CommonDialog1.Flags = cdlOFNExplorer Or cdlOFNHideReadOnly
    ' Set filters
    CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files" & _
    "(*.txt)|*.txt|Batch Files (*.bat)|*.bat"
    ' Specify default filter
    CommonDialog1.FilterIndex = 1
    ' Display the Open dialog box
    CommonDialog1.ShowOpen
    ' Display name of selected file
    UploadFile = CommonDialog1.FileName
    Exit Sub
  Else
  Dim strResFolder As String
   strResFolder = BrowseForFolder(hWnd, "Please select a folder.")
    If strResFolder = "" Then
       Call MsgBox("The Cancel button was pressed.", vbExclamation)
    Else
    UploadFile = strResFolder
    End If
    CommonDialog1.
    
ErrHandler:
    'User pressed the Cancel button
    Exit Sub
 End If
End Sub
Are you saying that I can just set the Command1 button to lostfocus?