Uma possibilidade:
Exclua o modulo nome "Mod1" e altere o Modulo nome:"mdConect" conforme abaixo
Observação: Nas rotinas, caso apareca a mensagem de variável nao definida "Caminho" altere para "CaminhoArquivo"
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public rsNro As ADODB.Recordset
Public rsOrçDet As ADODB.Recordset
Public rsOrçGrad As ADODB.Recordset
Public rsCadEmp As ADODB.Recordset
Public CaminhoArquivo As String
Public Provedor As String
Public sql As String
Public Tabela As String
Public indice As String
Public sqlNro As String
Public SqlOrçDet As String
Public SqlOrçGrad As String
Public sqlCadEmp As String
Public Flag As Boolean
Public BancoAberto As Boolean
Public ChangeTable As Boolean
Public campo As String
Public lst As ListItem
Public Incompleto As Boolean
Public ms As String
Public AçaoExecutadaPesquisa As Boolean
Public Fechar As Boolean
Public Cancela As Integer
'--Variáveis-Cálculo-----------------------------------------------------------------
Public CusTotal As Double
Public MediaMarg As Double
Public LucroTotal As Double
Public TotalOrç As Double
Public TotalBruto As Double
Public calc As Boolean
'--Outras-Variáveis------------------------------------------------------------------
Public NroOrç As Long
Public Inc As Boolean 'Para definir se está incluindo ou alterando um orçamento
Public iCancel As Integer 'Para bloquear ou desbloquear o fechamento do formulário
'----------cores----------------
Public Const Verde = &HC0FFC0
Public Const Amarelo = &HC0FFFF
Public Const Azul = &HFF0000
Public Const Vermelho = &HFF&
Public Const Preto = &H80000008
Public Const Cinza = &H8000000F
Public Const Branco = &H80000005
Sub Conectar()
Provedor = "Microsoft.ACE.OLEDB.12.0;DATA SOURCE="
CaminhoArquivo = ThisWorkbook.Path & "Banco.accdb"
'Sql = "SELECT * FROM " & Tabela
cn.Provider = Provedor & CaminhoArquivo
cn.Open
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.PageSize = 42
rs.Open sql, cn, adOpenKeyset, adLockOptimistic
End Sub
Sub Desconectar()
Set rs = Nothing
cn.Close
End Sub
Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel
Postado : 09/01/2017 7:12 am