Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version


There are a few methods to connect to a database from Calc.

You have stated that you have a DB already registered. The connection to the base file is easy using the registered name.

Sub ConnectDB
    Dim oContext As Object
    Dim oDB        As Object
    Dim oCon      As Object
    oContext = CreateUnoService("")
    oDB = oContext.getByName("Registered_Name_Here")
    oCon = oDB.getConnection("User_Name_Here","Password_Here") 
End Sub

oCon is the connection you can use to perform your SQL with such as:

  oStatement = oCon.CreateStatement()
  oResult = oStatement.executeQuery(sSQL)
  Do While
      Print oResult.getString(1)

If you want to bypass the Base file and connect directly to the Database, then the basic directions can be found in the AndrewBase document found here -> Andrew Pitonyak Documents. Look at page 106 - 8.6.6. Paradox using ODBC. This was the basis for my answer on this post -> Connect to mssql (ODBC) database via Macro.