Skip to main content

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.


Following is the complete getDbsConString function:
Function getDbsConString() As String
  Dim strProvider As String
  Dim strPassword, strPWD As String
On Error GoTo Err_Msg
  strProvider = "MS ACCESS"
  strPassword = ""
  If strPassword <> "" Then strPWD = ";PWD=" & strPassword Else strPWD = ""
  getDbsConString = strProvider & strPWD
Exit_Function:
  Exit Function
Err_Msg:
  MsgBox "Function getDbsConString, Error # " & str(Err.Number) & ", source: " & Err.Source & _
  Chr(13) & Err.description
  Resume Exit_Function
End Function

Implementation:


Setting the strProvider and strPassword as follows:
strProvider = "MS ACCESS"
strPassword = "abcd"
we get the connection string as follows:
getDbsConString = strProvider & strPWD
getDbsConString = "MS ACCESS;PWD=abcd"

Comments

Popular posts from this blog

Creating Master Table for Subaccounts

In our accounting database, we have two subaccounts that are part of the primary accounts. They are some sort of derivative accounts for the primary accounts. The two subaccounts may serve as profit center, cost center, organization unit, vendor, customer, tax, etc. The subaccounts are stored in two tables, one for subaccounts 1 and the other for subaccounts 2. Following are the explanation for both two tables.

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.