Skip to main content

Get Database Location

To get database location, we use getDbsLocation function to specify Access database location that will be opened. It is using strResult variable that can be a string value or expressions. The function result is a string file path name. The complete getDbsLocation function is as follows:

Function getDbsLocation() As String
  Dim strResult as String
On Error GoTo Err_Msg
  strResult = "D:\Access\Database_be.accdb"
  getDbsLocation = strResult 
Exit_Function:
  Exit Function
Err_Msg:
  MsgBox "Function getDbsLocation, Error # " & str(Err.Number) & ", source: " & Err.Source & _
  Chr(13) & Err.description
  Resume Exit_Function
End Function

Implementation:


If the strResult variable is  string value, then write the file path name, as can be seen in the above function. The function above use "D:\Access\Database_be.accdb" string value as the database location.

If the srtResult variable is an expression, then set the strResult value using expression. Example:

strResult = DLookup("[Database file path name]","[Table name]","[pathDefaultStatus]=True")
where [Database file path name] is the field that its value is taken from table [Table name] and it is set as database default, indicated by field [pathDefaultStatus]=True.

Table name
pathfFile pathDescription pathDefaultStatus
D:\Access\Database_be.accdb Local database True
\\Access\Database_be.accdb Server Database False

Using the table [Table name] above, we can control strResult to select D:\Access\Database_be.accdb as the database location. Therefore, the strResult expression is as follows:

strResult = DLookup("[pathfFile]","[Table name]","[pathDefaultStatus]=True")
or

strResult = "D:\Access\Database_be.accdb"

Comments

Popular posts from this blog

Get Connection String to Access DAO Database

To specify the connection string to a database, we use getDbsConString function. There are, at least, two variables to be set to specify the connection string. They are strProvider and strPassword. The strProvider variable specifies database provider to be employed, for example: the provider for MS Access database is MS Access. If the connection string has a password, then the strPassword variable must also be set. The result of getDbsConString function is a string value.

Function to Retrieve the Precision and Scale Property for Decimal Data Type

The uniqueness of decimal data type in Access are the existing properties named Precision and Scale. Precision property refers to the maximum number of digits in a number. Meanwhile, Scale property is the number of digits to the right of the decimal point in a number. Say for example, 123.45 has a precision of 5 and a scale of 2.

Get Connection String to Access ADO Database

Besides using DAO, a connection string to a database using ADO can also be set. In ADO connection string, we use at least four constants to be set to specify the connection string. They are constStrProvider,constStrDataSource, constStrUserId, and constStrPassword. The constStrProvider Const specifies database provider to be employed, for example: the provider for MS Access database is Microsoft.ACE.OLEDB.12.0. The constStrDataSource Const refers to the database file path. The constStrUserId Const refers to user identity, if the database use access level. If the connection string has a password, then the constStrPassword Const must also be set.