0% found this document useful (0 votes)
6 views11 pages

Public Sub CBEditar

Uploaded by

rafqwer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Public Sub CBEditar

Uploaded by

rafqwer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Provider=Microsoft.ACE.OLEDB.12.

0;Data Source=C:\myFolder\
myAccessFile.accdb;Persist Security Info=False

Public Sub CBEditar_Click()

On Error GoTo Erro

Exit Sub

Erro:

MsgBox "Erro!", vbCritical, "ERRO"

End Sub

Public Sub CBExcluir_Click()

On Error GoTo Erro

Exit Sub

Erro:

MsgBox "Erro!", vbCritical, "ERRO"

End Sub
Public Sub CBLimpar_Click()

On Error GoTo Erro

Call Limpar

Exit Sub

Erro:

MsgBox "Erro!", vbCritical, "ERRO"

End Sub

Public Sub CBPesquisar_Click()

On Error GoTo Erro

Dim Pesquisa As String

Pesquisa = InputBox("Digite uma Pesquisa ", "Pesquisar")

Dim Linha As Double

Linha = 1

With Plan1

Do

Linha = Linha + 1
Loop Until .Cells(Linha, 2).Value = ""

.Cells(Linha, 2).Value = ID

.Cells(Linha, 3).Value = Prestador.Text

.Cells(Linha, 4).Value = TEnt.Text

.Cells(Linha, 5).Value = TSaid.Text

.Cells(Linha, 6).Value = TDoutor.Text

.Cells(Linha, 7).Value = TPaciente.Text

.Cells(Linha, 8).Value = TTrabalho.Text

.Cells(Linha, 9).Value = TValor.Text

Call Limpar

MsgBox "Salvo com sucesso!", vbInformation, "SALVAR"

End With

Exit Sub

Erro:

MsgBox "Erro!", vbCritical, "ERRO"

End Sub

Public Sub CBSalvar_Click()

On Error GoTo Erro

If TId = "" Then


TId = WorksheetFunction.Max(Plan1.Range("B1:B1000000")) + 1

End If

Dim Ver As Double

Ver = WorksheetFunction.CountIf(Plan1.Range("B:B"), TId)

If Ver > 0 Then

MsgBox "Código ja cadastrado!", vbCritical, "ERRO"

Exit Sub

End If

If TPrestador = "" Or TEnt = "" Or TSaid = "" Or TDoutor = "" Or TPaciente = "" Or TTrabalho =
"" Or TValor = "" Then

MsgBox "Precisa preencher todos os campos!", vbCritical, "ERRO"

Exit Sub

End If

Dim Ent As Date

Ent = TEnt.Value

Dim Linha As Double

Linha = 1

Dim ID As Double

ID = TId

With Plan1
Do

Linha = Linha + 1

Loop Until .Cells(Linha, 2).Value = ""

.Cells(Linha, 2).Value = ID

.Cells(Linha, 3).Value = Prestador.Text

.Cells(Linha, 4).Value = TEnt.Text

.Cells(Linha, 5).Value = TSaid.Text

.Cells(Linha, 6).Value = TDoutor.Text

.Cells(Linha, 7).Value = TPaciente.Text

.Cells(Linha, 8).Value = TTrabalho.Text

.Cells(Linha, 9).Value = TValor.Text

Call Limpar

MsgBox "Salvo com sucesso!", vbInformation, "SALVAR"

End With

Exit Sub

Erro:

MsgBox "Erro!", vbCritical, "ERRO"

End Sub
Public Sub UserForm_Initialize()

TEnt = VBA.Date

End Sub

Sub Limpar()

TId = ""

TPrestador = ""

TEnt = ""

TSaid = ""

TDoutor = ""

TPaciente = ""

TTrabalho = ""

TValor = ""

End Sub

Public Conexao As ADODB.Connection

Public rs As ADODB.Recordset

Sub ConectarBD()

'On Error GoTo Erro

Dim strConexao As String


Set Conexao = New ADODB.Connection

strConexao = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\rafae\Documents\


BD_Acces\BD_CADASTRO.accdb;Persist Security Info=False"

Exit Sub

Erro:

MsgBox "Erro!", vbCritical, "ERRO"

End Sub
Public Conexao As ADODB.Connection

Public rs As ADODB.Recordset

Sub ConectarBD()

On Error GoTo Erro

Dim strConexao As String

Set Conexao = New ADODB.Connection

strConexao = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\rafae\Documents\


BD_Acces\BD_CADASTRO.accdb;Persist Security Info=False"

Conexao.Open strConexao

Exit Sub

Erro:

MsgBox "Erro!", vbCritical, "ERRO"

End Sub

Sub DesconectarDB()
If Not Conexao Is Nothing Then

Conexao.Close

Set Conexao = Nothing

End If

End Sub

Sub Salvar()

On Error GoTo Erro

Set rs = New ADODB.Recordset

ConectarBD

rs.Open "SELECT * FROM Tabela1", Conexao, adOpenKeyset, adLockPessimistic

rs.AddNew

rs!Prestador = UserForm.TPrestardor.Text

rs!Ent = VBA.Format(UserForm1.TEnt.Value, "dd-mm-yyyy")

rs!Said = VBA.Format(UserForm1.TSaid.Value, "dd-mm-yyyy")

rs!Doutor = UserForm.TDoutor.Text

rs!Paciente = UserForm.TPaciente.Text

rs!Trabalho = UserForm.TTrabalho.Text

rs!Valor = UserForm.TValor.Text

rs.Update

MsgBox "Salvo com Sucesso!", vbInformation, "Salvar"

If Not rs Is Nothing Then

rs.Close
Set rs = Nothing

End If

DesconectarDB

Exit Sub

Erro:

MsgBox "Erro!", vbCritical, "ERRO"

End Sub

You might also like