Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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()
    Me.Tag = CurDir

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
    strFolderPath = CurDir

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

    Me.Tag = strFolderPath
Exit Sub

End Sub
share|improve this question
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
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
@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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .