vb: how to check file existence?
This site provides users with the information about vb, visual basic, vb6, check file existence, how to check file existence, and more.
If you think that this site is helpful, please recommend your friends to visit our site.
How to check file exsitence?
The following are the steps to check file existence:
1. Create a Sub with the following code:
2. Add the following Function in BAS module
Private Sub Command1_Click()
If FileExists(App.Path + "\test.dat") Then
Open App.Path + "\test.dat" For Random As #1 Len = 100
MsgBox "The file '" + App.Path + "\test.dat' does not exist.", _
vbCritical + vbOKOnly, "File not found"
Public Function FileExists(FileName As String)
On Error Resume Next
FileExists = (Len(Dir(FileName)) > 0)