Private cnn As ADODB.Connection
Private rs As ADODB.Recordset
Private Sub Form_Load()
'instancia
On Error GoTo errConexao
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnn.Open "Provider=MSDASQL.1;Persist Security Info=False;User D=postgres;Data Source=empresa"
'retorna registros da tabela
rs.Open "Select * from tabela", cnn, adOpenStatic, adLockOptimistic
errConexao:
With Err
If .Number <> 0 Then
MsgBox "Houve um erro na conexão com o banco de dados." & _
vbCrLf & "O sistema será encerrado.", _
vbCritical + vbOKOnly + vbApplicationModal, _
"Erro na conexão"
.Number = 0
Set rs = Nothing
Set cnnEmpresa = Nothing
End
End If
End With
End Sub