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

Functions to Open and Close DAO Database

This post describes how to create functions to open and close MS Access database. The functions involve two common methods provided by MS Access, they are OpenDatabase and Close. Opening a database, especially  used in connecting to tables and queries is the first process in accessing database. Meanwhile, closing a database is the last process in accessing database.

Get Current Database

In a back-end database environment, we almost never create table or query in Access database that executed as the current application. Access database that executed as the current application, also known as front-end database, is almost never used to store a table or query. In most case, the table or query stored in the front-end database is temporary in nature, so that later will be deleted soon after no longer needed.

Function to Get Data Type DAO

Data type is the most important property in a field. Data type determines what type of data should be stored in a field of a table and how to present the data in a report. For example, a field with Text data type stores data in a text or numerical character. For a field that has Numeric data type, this field can only stores numerical data.