0

I have a form that contains two text boxes where the user can type in file paths, I want to check to see if the file path entered into the textboxes are valid when the user clicks on the accept button. Here is my code

Private Sub btnAccept_Click()

Dim OpenFile As Integer

OpenFile = FreeFile

'Create and write to .ini file
Open App.Path & "\HistoricalPlayback.ini" For Output As OpenFile
    Print #OpenFile, "File Configuration: " & txtFFP
    Print #OpenFile, "Database Configuration: " & txtDBFP
Close OpenFile

If Dir$(txtFFP.Text) <> "" Or Dir$(txtDBFP.Text) <> "" Then
    Exit Sub
Else
    MsgBox "Enter Valid File Path"
End If
   
glbFilePath = txtFFP.Text
glbDBPath = txtDBFP.Text
End Sub
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Jx_Man
0

add this function :

Function FileExists(FileName As String) As Boolean
    On Error GoTo ErrorHandler
    ' get the attributes and ensure that it isn't a directory
    FileExists = (GetAttr(FileName) And vbDirectory) = 0
ErrorHandler:
    ' if an error occurs, this function returns False
End Function
Private Sub btnAccept_Click()

Dim OpenFile As Integer

OpenFile = FreeFile

'Create and write to .ini file
Open App.Path & "\HistoricalPlayback.ini" For Output As OpenFile
    Print #OpenFile, "File Configuration: " & txtFFP
    Print #OpenFile, "Database Configuration: " & txtDBFP
Close OpenFile

[B]If FileExists(txtFFP.text) = True And FileExists(txtDBFP.Text) = True Then
    MsgBox "File Path is Valid"[/B]
Else
    MsgBox "Enter Valid File Path"
End If
   
glbFilePath = txtFFP.Text
glbDBPath = txtDBFP.Text
End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.