Validation is one of the important parts of any programming language. As per few studies, 60% of the code is focused on validating input or output.
In this article, we will explain 2 methods to validate if the given folder path is valid or not.
The below VBA function uses the Dir VBA function to validate Folder Path.
'This function checks if given folder path is valid or not
Public Function CheckFolderExist(strFolderPath As String) As Boolean
'If Dir retunrs blank then it is invalid folder path
If Dir(strFolderPath, vbDirectory) = "" Then
CheckFolderExist = False
MsgBox "Invalid Folder Path!", vbCritical
'Else it is a valid folder path
Else
CheckFolderExist = True
MsgBox "Valid Folder Path!", vbInformation
End If
End Function
Explanation: If the function returns True then it is a valid folder path. If function returns False then it is invalid folder path.
Below VBA function uses File System Object to validate Folder path
'This function checks if given folder path is valid or not
'Microsoft Scripting Runtime reference is required to run this code
Public Function CheckFolderExist(strFolderPath As String) As Boolean
Dim objFileSystem As FileSystemObject
Set objFileSystem = New FileSystemObject
'If FolderExists function returns True then it is valid folder path
If objFileSystem.FolderExists(strFolderPath) = True Then
CheckFolderExist = True
MsgBox "Valid Folder Path!", vbInformation
'Else it is invalid folder path
Else
CheckFolderExist = False
MsgBox "Invalid Folder Path!", vbCritical
End If
End Function
Explanation: If the function returns True then it is a valid folder path. If function returns False then it is invalid folder path.
In MS Access, the best way to create a multiuser tool is to divide your solution. One part acts as interface and other one acts as database. You can have multiple copies of the interface distributed to users which are connected to central MS Access database saved at common shared drive. To connect the interface to database, you can use link table feature (Access>External Data>Import & Link) available in MS Access. Below is a commonly required VBA code which helps the developers to re-link MS Access linked tables when the database is renamed or moved to other location
How to use VBA to open Workbook in Excel? There are few VBA codes which are commonly used by every developer. One of them is giving an option to user to browse a file. Below is a…
VBA Code To Delete All Shapes On A Excel sheet Here is a VBA code which deletes all the shapes from an Excel sheet. Code is simple but you have to be bit careful while…
VBA code that will sum cells by its color through excel function. This code will really help in making the analysis and presentation better.
VBA Code to Read Outlook Emails Reading emails from Outlook and capture them in Excel file is very common activity being performed in office environment. Doing this activity manually every time is quite boring and…
Did you come across any requirement where you want the user to interact with a sheet only through VBA Form? Here is a simple code which can help you.