Consulting

Results 1 to 3 of 3

Thread: Server login

  1. #1

    Server login

    Hello, I am trying to modify the code below, so that if the path does not exist then prompt the user for id and password and then login to the server.


    [VBA] Sub FolderExists()
    Dim fso
    Dim folder As String
    folder = "\\server\shr\mcl" ' change to match the folder path
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FolderExists(folder) Then
    MsgBox folder & " is a valid folder/path.", vbInformation, "Path Exists"
    Else
    MsgBox folder & " is not a valid folder/path.", vbInformation, "Invalid Path"
    End If
    End Sub
    [/VBA]

  2. #2
    VBAX Master XLGibbs's Avatar
    Joined
    Jan 2006
    Location
    state of confusion, but vacation in denial
    Posts
    1,315
    Location
    Hi, you don't need the file system object for this..

    [VBA] Dim x As String


    myPath = "D:\My Documents\" 'set the path up here to look for

    On Error Resume Next
    x = GetAttr(myPath) And 0
    If Err = 0 Then PathExists = True _
    Else: PathExists = False
    If PathExists = False Then
    MsgBox "Path does not exist"Exit Sub
    'you can enter default path settings here or other actions to handle no path
    End If[/VBA]

    'down here you could have all of your "IF TRUE" code for once the path exists..

    Hope it helps.

  3. #3

    Re: Server login

    To check if a file or directory exists you could also use this routine:

    [VBA]Sub FilePathExists()
    Dim strPathandFile As String
    strPathandFile = "path+file" ' <- Change to your path and filename
    If Dir(strPathandFile) = "" Then
    MsgBox (strPathandFile & " does not exist")
    Else
    MsgBox (strPathandFile & " exists")
    End If
    End Sub [/VBA]

    If you just want to check of a directory just add a backslash at the end of strPathandFile, for example "C:\Windows\" in stead of "C:\Windows". The latter will cause the routine to look for a file (not directory) called "Windows" in the root of your C drive.

    Rembo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •