Access: CurDir Function

In Access, the CurDir function returns a string containing the full path of the specified drive. 

The syntax for the CurDir function is:

CurDir ( drive )

The optional drive argument is a string expression that specifies an existing drive. If this parameter is omitted or it is a zero-length string (“”), CurDir returns the path for the current drive.

Example

CurDir ()             returns "C:\Documents and Settings\UserName\My Documents" 
CurDir ( "H" )        returns "H:\"

VBA Code

Dim MyPath As String 
MyPath = CurDir ()

This example uses the CurDir function to return the current path. Now the MyPath variable would contain the value “C:\Documents and Settings\UserName\My Documents”.

SQL query

You can also use the CurDir function in a query.

SELECT CurDir() AS Expr1
FROM Orders

Note

This function cannot be used or referenced in expressions when Access is operating in sandbox mode, but they can be used in Microsoft Visual Basic for Applications (VBA) code. To enable the CurDir function in expressions or SQL statements, add the following code to a code module in the Visual Basic Editor in Access:

Public Function CurDir(Optional Drive As String) 
CurDir = VBA.CurDir(Drive)
End Function
admin

admin

Leave a Reply

Your email address will not be published.