Function Get Filename from File Path

Function: Function GetFilenameFromPath(ByVal strPath As String) As String On Error GoTo errorhandler If Right$(strPath, 1) <> “\” And Len(strPath) > 0 Then GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) – 1)) + Right$(strPath, 1) End If errorhandler: Exit Function End Function How to Use It: The above function will return a file name with its extension. It returns the rightmost characters of a string up to, but not including the rightmost ‘\’. You can call this function as: Dim myPath as String myPath = “C:\myFolder\MyDoc.doc” call GetFilenameFromPath(myPath) it will return “MyDoc.doc”

Read More

Function Check If Folder Exists

Function Test If Folder Exists VBA Code: Function FolderExists(sFile As Variant) As Boolean On Error Resume Next If Len(sFile) > 0 Then     FolderExists = (Len(Dir$(sFile, vbDirectory)) > 0&) End If End Function How to Use It: Put the VBA code above on form or in the Module and call it on the click button on your Access file where you want to check if this form exists before call process the next step. If you call a certain folder or file path that does not exist then you will get…

Read More

How to Create a Random Letter and Number

How to Create a Random Letter and Number Function In this How To, I will demonstrate how to create a random function for alphabets (letter) and numbers. We can use the random string in our program such as to reset a password, create a reference number, create a product ID, etc. I will also show how to mix the random letter and number into a string. The random function will need a built-in Rnd() function which returns a value less than 1 but greater than or equal to zero. The…

Read More

How to Create Sub Procedure or Function Procedure

How to Create Sub Procedure or Function Procedure A Sub procedure is a series of Visual Basic statements that start with the Sub and end with End Sub. A Function procedure is a series of Visual Basic statements that start with the Function and end with End Function. The Sub and Function procedure perform a task and then returns control to the calling code. However, the Sub procedure does not return a value to the calling code, but the Function procedure returns a value to the calling code. A Sub…

Read More

How to Use DLookup Function

Use DLookup() Function in MS Access DLookup function is a built-in function to get the value of a particular field from the set of records or data from table, query, SQL, or Recordset. The result of DLookup function will be the particular field of the first record. DLookup Syntax DLookup(Expression, Domain, Criteria [optional]) Expression identifies the field whose value you want to return. It can be a string expression identifying a filed in a table or query. Domain is a set of records. It can be a table name or…

Read More

How to Use DCount Function

Use DCount() Function in MS Access DCount function is a built-in function to get the number of records from the set of records or data from table, query, SQL, or Recordset. We can use the DCount function in Visual Basic and macro. DCount Syntax DCount(Expression, Domain, Criteria [optional]) Expression identifies the field that you want to count records. It can be a string expression identifying a filed in a table or query. Domain is a set of records. It can be a table name or a query name for a…

Read More

Function Days In Month()

***Function DaysInMonth() *** This function will generate a number of days from the input month. For example, if 6/4/2016 is input into the function like DaysInMonth(6/4/2016) the result will be “30” as June has 30 days in the month. The LeapYear function also is used in the DaysInMonth function. VB Code: How to Use It: You can put the above functions on current form or in the Module. If you want to know the number of days of the month from the input date the function will be like: Input…

Read More