PDA

View Full Version : Server login



mbrwny20
01-19-2006, 02:17 PM
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.


Sub FolderExists()
Dim fso
Dim folder As String
folder = "\\server\shr\mcl (file://%5Cservershrmcl)" ' 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

XLGibbs
01-19-2006, 05:14 PM
Hi, you don't need the file system object for this..

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

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

Hope it helps.

Rembo
01-22-2006, 09:36 AM
To check if a file or directory exists you could also use this routine:

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

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