NUNCA MAIS PASSE RAIVA POR NÃO CONSEGUIR RESOLVER UM PROBLEMA COM O EXCEL - GARANTIDO!
UNIVERSIDADE DO VBA - Domine o VBA no Excel Criando Sistemas Completos - Passo a Passo - CLIQUE AQUI
Objetivo:
O objetivo deste tutorial é continuar o desenvolvimento do sistema mototáxi, neste iremos criar o banco de dados para armazenar registrosdos funcionários, utilizaremos a tarceira planilha do excel, também iremos codificar oformulário funcionário, tudo de forma simples e direta.
Pré-requisito:
Para você poder acompanhar odesenvolvimento deste tutorial, será necessário ter conhecimento no mínimo do “CursoBásico de Excel e os Tutoriais Utilizando Editor do Visual Basic do Excel Parte1 e Parte2” Parte 1, Parte 2, Parte 3, Parte 4 e Parte 5 deste tutorial.
Modifique o nome da planilha 3 para “FUNCIONARIO”, depois vamos colocar os nomesdos campos relacionados abaixo.
COD, NOME, ENDERECO, BAIRRO, CIDADE, TELEFONE, EMAIL, CEP,RG, CPF, VEICULO, PLACA, COR.
Tela 001
Neste campos iremos colocar cor cinza, negrito ecentralizados.
Tela 002
Vamos formatar os campo, sendo que a formataçãoirei mostrar através de telas só aprimeira parte, depois apenas irei dizer com quais formatações que os camposdevem permanecer.
COD, RG, CPF, VEICULO e PLACA colocar na categoria “Geral”.
Tela 003
O restante dos campos devem serformatados da seguinte maneira:
NOME, ENDERECO, BAIRRO, CIDADE,EMAIL e COR inserir na categoria“texto”.
TELEFONE para categoria “ Especial,Telefone”.
CEP para categoria “Especial, Cep”.
Concluido o desenvolvimento do banco de dados, começaremos a codificar a interface funcionário, insira o código abaixo no formulário, dentro do evento initialize.
Label_n =Application.WorksheetFunction.CountA(Plan3.Columns(1)) – 1
Tela 004
Começaremos a inserir os códigos nos botões, no evento clic dos mesmos.
BotãoCadastrar:
Dim bd As Database
Dim Rs As Recordset
Set bd =OpenDatabase(ThisWorkbook.Path & "\" & ThisWorkbook.Name,False, False, "excel 8.0")
Set Rs =bd.OpenRecordset("FUNCIONARIO$", dbOpenDynaset)
If Me.Text_cod >Me.Label_n Then
If Me.Text_nome = "" Then
Me.Text_nome.Text ="-"
End If
If Me.Text_bairro = ""Then
Me.Text_bairro.Text ="-"
End If
If Me.Text_cep = "" Then
Me.Text_cep.Text ="-"
End If
If Me.Text_cidade = ""Then
Me.Text_cidade.Text ="-"
End If
If Me.Text_cod = "" Then
Me.Text_cod.Text ="-"
End If
If Me.Text_cor = "" Then
Me.Text_cor.Text ="-"
End If
If Me.Text_cpf = "" Then
Me.Text_cpf.Text ="-"
End If
If Me.Text_email = ""Then
Me.Text_email.Text ="-"
End If
If Me.Text_endereco = ""Then
Me.Text_endereco.Text ="-"
End If
If Me.Text_rg = "" Then
Me.Text_rg.Text = "-"
End If
If Me.Text_placa = ""Then
Me.Text_placa.Text ="-"
End If
If Me.Text_veiculo = ""Then
Me.Text_veiculo.Text ="-"
End If
Dim CADASTRO(1 To 14)
CADASTRO(1) = UCase(Me.Text_cod)
CADASTRO(2) = UCase(Me.Text_nome)
CADASTRO(3) = UCase(Me.Text_endereco)
CADASTRO(4) = UCase(Me.Text_bairro)
CADASTRO(5) = UCase(Me.Text_cidade)
CADASTRO(6) = UCase(Me.Text_telefone)
CADASTRO(7) = UCase(Me.Text_email)
CADASTRO(8) = UCase(Me.Text_cep)
CADASTRO(9) = UCase(Me.Text_rg)
CADASTRO(10) = UCase(Me.Text_cpf)
CADASTRO(11) = UCase(Me.Text_veiculo)
CADASTRO(12) = UCase(Me.Text_placa)
CADASTRO(13) = UCase(Me.Text_cor)
CADASTRO(14)= UCase(Me.Text_cod.Value)
Dim MOTOTAX AsObject
Dim L, i
Set MOTOTAX = Plan3.Cells(1,1).CurrentRegion
L = MOTOTAX.Rows.Count + 1
If Len(Me.Text_cod) = 0 Then
MsgBox "VOCÊ NÃODIGITOU NENHUM NOME PARA INCLUSÃO", vbCritical, "CADASTRO DECLIENTES"
Else
For i = 1To 14
Plan3.Cells(L, i).Value = Trim(CADASTRO(i))
Next i
Me.Text_cod.Text = ""
Me.Text_nome.Text =""
Me.Text_bairro.Text =""
Me.Text_cep.Text = ""
Me.Text_cidade.Text =""
Me.Text_telefone.Text =""
Me.Text_cod.Text = ""
Me.Text_cor.Text = ""
Me.Text_cpf.Text = ""
Me.Text_email.Text =""
Me.Text_endereco.Text =""
Me.Text_rg.Text = ""
Me.Text_placa.Text =""
Me.Text_veiculo.Text =""
MsgBox"CADASTRADO", vbInformation, "EFETUADO COM SUCESSO"
ThisWorkbook.Save
End If
Exit Sub
Else
MsgBox "No campo CODIGO digite um número maior do quehá no campo Total Registro para casdastrar."
End If
Universidade do VBA - Curso Completo, com Certificado e com Atualizações Semanais
Domine, sem Dificuldades, a Programação VBA no Excel, Através da Criação de Sistemas Profissionais Completos - Com Exemplos Práticos e Explicações Detalhadas - Passo a Passo - Tela a Tela - Comando a Comando!
Aplica-se ao Excel 2019, 2016, 2013 e 2010!
Para todos os detalhes, acesse:
Tela 005
BotãoPesquisar:
Dim bd As Database
Dim Rs As Recordset
Dim LIN
Set bd =OpenDatabase(ThisWorkbook.Path & "\" & ThisWorkbook.Name,False, False, "excel 8.0")
Set Rs =bd.OpenRecordset("FUNCIONARIO$", dbOpenDynaset)
LIN = 2
Do Until Rs.EOF
If Rs("NOME") =Me.Text_nome.Text Then
Me.Text_cod =Rs.Fields("COD")
Me.Text_nome =Rs.Fields("NOME")
Me.Text_endereco =Rs.Fields("ENDERECO")
Me.Text_bairro =Rs.Fields("BAIRRO")
Me.Text_cidade =Rs.Fields("CIDADE")
Me.Text_telefone =Rs.Fields("TELEFONE")
Me.Text_email =Rs.Fields("EMAIL")
Me.Text_cep =Rs.Fields("CEP")
Me.Text_rg =Rs.Fields("RG")
Me.Text_cpf =Rs.Fields("CPF")
Me.Text_veiculo = Rs.Fields("VEICULO")
Me.Text_placa =Rs.Fields("PLACA")
Me.Text_cor =Rs.Fields("COR")
Me.TextBox_codf.Text = LIN
End If
LIN = LIN + 1
Rs.MoveNext
Loop
Tela 006
Botão Editar:
Dim bd As Database
Dim Rs As Recordset
Set bd =OpenDatabase(ThisWorkbook.Path & "\" & ThisWorkbook.Name,False, False, "excel 8.0")
Set Rs =bd.OpenRecordset("FUNCIONARIO$", dbOpenDynaset)
Rs.Edit
Rs("NOME") = Me.Text_nome
Rs("ENDERECO") = Me.Text_endereco
Rs("BAIRRO") = Me.Text_bairro
Rs("CIDADE") = Me.Text_cidade
Rs("TELEFONE") = Me.Text_telefone
Rs("EMAIL") =Me.Text_email
Rs("CEP") =Me.Text_cep
Rs("RG") =Me.Text_rg
Rs("CPF") =Me.Text_cpf
Rs("VEICULO") = Me.Text_veiculo
Rs("PLACA") = Me.Text_placa
Rs("COR") =Me.Text_cor
Rs.Update
MsgBox "DADOS DOFUNCIONÁRIO ALTERADOS COM SUCESSO", vbInformation, "BANCO DEDADOS"
ThisWorkbook.Save
Tela 007
Botão Apagar:
Dim MOTOTAX
MOTOTAX =MsgBox("DESEJA REALMENTE EXCLUIR O CLIENTE?", vbYesNo + vbQuestion,"BANCO DE DADOS")
If MOTOTAX = vbYes Then
Plan3.Cells(Me.TextBox_codf,1).EntireRow.Delete
Me.Text_cod.Text = ""
Me.Text_nome.Text =""
Me.Text_bairro.Text = ""
Me.Text_cep.Text = ""
Me.Text_cidade.Text =""
Me.Text_telefone.Text = ""
Me.Text_cod.Text = ""
Me.Text_cor.Text = ""
Me.Text_cpf.Text = ""
Me.Text_email.Text =""
Me.Text_endereco.Text =""
Me.Text_rg.Text = ""
Me.Text_placa.Text =""
Me.Text_veiculo.Text =""
MsgBox"REGISTROS EXCLUÍDO COM SUCESSO."
ThisWorkbook.Save
End If
Tela 008
Botão Voltar:
Me.hide
Neste tutorial ensinei você a criar o banco de dados para armazenar os dados dofuncionário, definindo as formataçõesnecessárias para cada campo, codificamos o formulário “funcionário”, tudo deforma simples e objetiva mostradoatravés de telas. Na próxima parte do tutorial daremos continuidade nodesenlvovimento do aplicativo. Bons estudos e até a próxima parte.
Contato: Telefone: (51) 3717-3796 | E-mail: webmaster@juliobattisti.com.br | Whatsapp: (51) 99627-3434
Júlio Battisti Livros e Cursos Ltda | CNPJ: 08.916.484/0001-25 | Rua Vereador Ivo Cláudio Weigel, 537 - Universitário, Santa Cruz do Sul/RS, CEP: 96816-208
Todos os direitos reservados, Júlio Battisti 2001-2025 ®
LIVRO: MACROS E PROGRAMAÇÃO VBA NO EXCEL 2016 - CURSO COMPLETO E PRÁTICO
DOMINE A PROGRAMAÇÃO VBA NO EXCEL - 878 PÁGINAS - CLIQUE AQUI