none
Global Variable, Userform, and Save Option RRS feed

  • Question

  • Morning All,

    Please I need help with the below code.

    It is always choosing the first option in the Module no matter what option I choose in the userform. Which is the personal drive. Thanks!!!

    User form Code:
    Private Sub Personalcmd_Click()
    If Me.ComboBox1.Value = "PERSONAL DRIVE" Then
    PersonalDrive = ComboBox1.Value
    ElseIf Me.ComboBox1.Value = "OPS-BAU" Then
    OPSDrive = ComboBox1.Value
    ElseIf Me.ComboBox1.Value = "ALL DRIVE" Then
    AlldriveDrive = ComboBox1.Value
    End If
    Unload Me

    End Sub

    Private Sub UserForm_Initialize()
    With ComboBox1
    .AddItem "PERSONAL DRIVE"
    .AddItem "OPS-BAU"
    .AddItem "ALL DRIVE"
    End With
    End Sub

    MODULE CODE

    Public PersonalDrive As String
    Public OPSCMD As String
    Public AlldriveCMD As String

    DriveOptionfrm.Show
    'Open personal
    If PersonalDrive = True Then
    Set objFolder = objShell.BrowseForFolder(lHwnd, "Select folder to save attachments:", OPTIONS, "S:\")

    'Opens Ops drive
    ElseIf OPSDrive = True Then
    Set objFolder = objShell.BrowseForFolder(lHwnd, "Select folder to save attachments:", OPTIONS, "M:\OPS-BAU")

    'Opens root
    ElseIf AlldriveDrive Then
    Set objFolder = objShell.BrowseForFolder(lHwnd, "Select folder to save attachments:", _
                                                         BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN, CSIDL_DESKTOP)
    End If

    Monday, July 24, 2017 2:00 PM

All replies

  • any help plz?
    Monday, July 24, 2017 3:18 PM
  • You can't compare string and Boolean variables:

    If PersonalDrive = True Then


    Instead, you need to use something like that:

    If str = "" Then 
      ' uninitialised, null or empty ""

    Also you may consider using the Len and Trim functions:

     HasContent = (Len(Trim(text_box.Value)) > 0)


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Monday, July 24, 2017 4:41 PM