Function Ligar_se_a_DB As Object
Dim DatabaseContext As Object
Dim oDataSource As Object
Dim InteractionHandler As Object
Dim sPwd As String
Dim MyString, x As String
Dim i as Integer
Dim Ligado As Boolean
i=909
x = CInt( i )
MyString = String(5, “0”) + x ’ Returns “*****”.
’ Usando Firebird via ODBC
’ Ligar-se à base de dados
DatabaseContext = createUnoService(“com.sun.star.sdb.DatabaseContext”)
oDataSource = DatabaseContext.getByName(“GestACRA”) ’ C:\Users\Minha Pasta\Documents\GestACRA.odb
’ ??? Ligado = oDataSource.IsConnect ??
If Not oDataSource.IsPasswordRequired Then
oConnection = oDataSource.GetConnection("","") ’ User/Pwd=Leitura apenas
Else
InteractionHandler = createUnoService(“com.sun.star.sdb.InteractionHandler”)
oConnection = oDataSource.ConnectWithCompletion(InteractionHandler)
'oConnection.SetReadOnly( False ) ‘’ não pode em ligações partilhadas
End If
If Not IsNull (oConnection) Then
If oConnection.ISCONNECT ??? Then
Ligar_se_a_DB = oConnection
Else
S MsgBox "Não foi possível. A ligação terminou em erro! "
End If
End Function ’ Ligar_se_a_DB
Atentamente
Mário Reis