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:
Continuar o desenvolvimento dosistema, criaremos neste tutorial o banco de dados para armazenar registros e codificação do formulário Dados_empresa, tudode 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 eParte 3 deste tutorial.
Utilizaremos a terceira planilhado excel, é essencial que você siga todos passos para que o sistema funcione, modifique o nome Plan3 para a “LINHA”, depois iremosinserir os nomes dos campos abaixo.
COD, EMPRESA, IE, CNPJ, ENDERECO, BAIRRO, CIDADE, ESTADO,eTELCOMERCIAL.
Tela 001
Agora temos que fazer uma formatação na primeira linha,coloque cor cinza, negrito ecentralizado os campos. Isso se faz necessário para que os campos fiquemindentificados como cabeçalho.
Tela 002
Vamos fazer as formatações em cada um dos campos s conformedescrição abaixo.
COD, IE, e CNPJcolocar na categoria “número”.
Tela 003
Os demais campos você deveseguir as formatações abaixo:
EMPRESA, ENDERECO, BAIRRO,CIDADE e ESTADO inserir na categoria“texto”.
Tela 004
TELCOMERCIAL inserir na categoria “especial”.
Tela 005
Concluído o desenvolvimento dobanco de dados, iremos codificar o sistema insira o código abaixo dentrodo evento initialize do formulário.
Label_n =Application.WorksheetFunction.CountA(Plan3.Columns(1)) – 1
Tela 006
Agora vamos inseriros códigos nos botões, no evento clic.
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("LINHA$", dbOpenDynaset)
If Me.text_cod >Me.Label_n Then
If Me.text_empresa = ""Then
Me.text_empresa = "-"
End If
If Me.Text_IE = "" Then
Me.Text_IE.Text = "-"
End If
If Me.Text_cnpj = "" Then
Me.Text_cnpj.Text ="-"
End If
If Me.Text_endereco = ""Then
Me.Text_endereco.Text ="-"
End If
If Me.text_bairro = ""Then
Me.text_bairro.Text ="-"
End If
If Me.Combo_cidade = ""Then
Me.Combo_cidade.Text ="-"
End If
If Me.Combo_estado = ""Then
Me.Combo_estado.Text ="-"
End If
If Me.Text_comercial = ""Then
Me.Text_comercial.Text ="-"
End If
Dim CADASTRO(1 To 10)
CADASTRO(1) = UCase(Me.text_cod)
CADASTRO(2) = UCase(Me.text_empresa)
CADASTRO(3) = UCase(Me.Text_IE)
CADASTRO(4) = UCase(Me.Text_cnpj)
CADASTRO(5) = UCase(Me.Text_endereco)
CADASTRO(6) = UCase(Me.text_bairro)
CADASTRO(7) = UCase(Me.Combo_cidade)
CADASTRO(8) = UCase(Me.Combo_estado)
CADASTRO(9) = UCase(Me.Text_comercial)
CADASTRO(10) = UCase(Me.text_cod.Value)
Dim VT As Object
Dim L, i
Set VT = Plan3.Cells(1,1).CurrentRegion
L = VT.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 = 1 To10
Plan3.Cells(L, i).Value = Trim(CADASTRO(i))
Next i
Me.text_cod.Text = ""
Me.text_empresa.Text =""
Me.Text_IE.Text = ""
Me.Text_cnpj.Text =""
Me.Text_endereco.Text =""
Me.text_bairro.Text =""
Me.Combo_cidade.Text = ""
Me.Combo_estado.Text = ""
Me.Text_comercial.Text = ""
MsgBox"CADASTRADO", vbInformation, "EFETUADO COM SUCESSO"
ThisWorkbook.Save
End If
Exit Sub
Else
MsgBox "No campo COD digite um número maior do que há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 007
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("LINHA$",dbOpenDynaset)
LIN = 2
Do Until Rs.EOF
If Rs("EMPRESA")= Me.text_empresa.Text Then
Me.text_cod =Rs.Fields("COD")
Me.Text_IE =Rs.Fields("IE")
Me.Text_cnpj =Rs.Fields("CNPJ")
Me.Text_endereco = Rs.Fields("ENDERECO")
Me.text_bairro = Rs.Fields("BAIRRO")
Me.Combo_cidade = Rs.Fields("CIDADE")
Me.Combo_estado = Rs.Fields("ESTADO")
Me.Text_comercial =Rs.Fields("TELCOMERCIAL")
Me.TextBox_codf.Text = LIN
End If
LIN = LIN + 1
Rs.MoveNext
Loop
Tela 008
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("LINHA$", dbOpenDynaset)
Rs.Edit
Rs("EMPRESA") = Me.text_empresa
Rs("IE") = Me.Text_IE
Rs("CNPJ") = Me.Text_cnpj
Rs("ENDERECO") = Me.Text_endereco
Rs("BAIRRO") = Me.text_bairro
Rs("TELCOMERCIAL") = Me.Text_comercial
Rs.Update
MsgBox"DADOS ALTERADOS COM SUCESSO", vbInformation, "BANCO DEDADOS"
ThisWorkbook.Save
Tela 009
Botão Apagar:
Dim VT
VT =MsgBox("DESEJA REALMENTE EXCLUIR O CLIENTE?", vbYesNo + vbQuestion,"BANCO DE DADOS")
If VT = vbYes Then
Plan3.Cells(Me.TextBox_codf,1).EntireRow.Delete
Me.text_cod.Text = ""
Me.text_empresa.Text =""
Me.Text_IE.Text = ""
Me.Text_cnpj.Text =""
Me.Text_endereco.Text =""
Me.text_bairro.Text =""
Me.Combo_cidade.Text =""
Me.Combo_estado.Text = ""
Me.Text_comercial.Text = ""
MsgBox"REGISTROS EXCLUÍDO COM SUCESSO."
ThisWorkbook.Save
End If
Tela 010
Botão Voltar:
Me.hide
Tela 011
Desenvolvemos o banco de dados, fazendo as formataçõesnecessárias para cada campo, codificamos a interface “DADOS_EMPRESA”, tudo deforma simples e objetiva mostradoatravés de telas. Na próxima parte do tutorial daremos continuidade nodesenlvovimento do sistema. 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