Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using the msoFileDialogFolderPicker to return a path when a user wants to deposit a report in a specific folder.

A custom form (ufSelRepType) shows up in the macro in cases where the default save location already has an output file or when the user does not wish to save to the default location. The custom form specifies a few common report save locations and gives the option to select an alternate location. Clicking button cmdCustom does the following:

Private Sub cmdCustom_Click()
    Application.FileDialog(msoFileDialogFolderPicker).Show
    Me.Tag = CurDir
    Me.Hide

End Sub

The code in the macro to handle the form output is simple:

 strSavePath = ufSelRepType.Tag

Selecting a folder, the string is always returned without a trailing "\". However, if a drive root is selected (we use mapped drives to our file server and so while this case may be rare, it is not an inconcievable scenario) the string returned ends with a "\".

How might I go about checking for the trailing "\" and handling it?

UPDATE: Per solution below, this is the new code for the form control cmdCustom:

Private Sub cmdCustom_Click()
    Dim strFolderPath As String

    'Getting save folder
    Application.FileDialog(msoFileDialogFolderPicker).Show
    strFolderPath = CurDir

    'Checking that path ends in \
    If Right(strFolderPath, 1) = "\" Then
        GoTo Complete
    Else:
        strFolderPath = strFolderPath & "\"
        GoTo Complete
    End If
Exit Sub

Complete:
    Me.Tag = strFolderPath
    Me.Hide
Exit Sub

End Sub
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Assuming that strSavePath is just a string then you can check if "\" is the right-most character:

If Right(strSavePath, 1) = "\" Then
  doSomething()
Else
  doSomethingElse()
End If
share|improve this answer
    
Brilliant. Thank you for this. The syntax of Right is Right(string, <integer number of characters to check>)? –  music2myear Apr 13 '11 at 19:08
1  
@music2myear - yes, the syntax is Right(string, length) where length: Required; Variant (Long). Numeric expression indicating how many characters to return. If 0, a zero-length string ("") is returned. If greater than or equal to the number of characters in string, the entire string is returned. –  Siim K Apr 13 '11 at 19:14
    
Ok, thank you. I've implemented it on the form itself because the form is used in a couple places in the macro and doing it there prevented code duplication. Works like a charm. –  music2myear Apr 13 '11 at 19:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.