Nessa tela o usurio ir entrar com seu nome e senha para ter acesso ao
sistema, lembrando que o nome e senha j devero estar cadastrados. Caso
o usurio no esteja cadastrado ser mostrada uma tela de erro com a
seguinte mensagem:
Aps ser validado no sistema ser exibida a tela de menu, onde ser
possvel acessar a rea de cadastro de produtos ou sair do sistema:
Cdigo VBA
Frm_Login
Private Sub UserForm_Activate()
Application.Visible = False
TBx_Senha.Enabled = TBx_Usuario.Text <> ""
CBt_Ok.Enabled = (TBx_Usuario.Text <> "" And TBx_Senha.Text <> "")
End Sub
Private Sub CBt_OK_Click()
Dim Linha As Integer
On Error GoTo NaoEncontrado
Linha = Sheets("Login").Range("A:A").Find(TBx_Usuario).Row
If TBx_Senha = Sheets("Login").Cells(Linha, 2) Then
MsgBox "Bem Vindo " & TBx_Usuario
Unload Me
Frm_Menu.Show
Else
MsgBox "A senha no confere"
TBx_Senha = ""
TBx_Senha.SetFocus
End If
Exit Sub
NaoEncontrado:
MsgBox "Usurio no cadastrado."
TBx_Usuario = ""
TBx_Usuario.SetFocus
End Sub
Private Sub TBx_Usuario_Change()
TBx_Senha.Enabled = TBx_Usuario.Text <> ""
CBt_Ok.Enabled = (TBx_Usuario.Text <> "" And TBx_Senha.Text <> "")
End Sub
Private Sub TBx_Senha_Change()
CBt_Ok.Enabled = (TBx_Usuario.Text <> "" And TBx_Senha.Text <> "")
End Sub
Frm_Menu
Private Sub CBt_CadProduto_Click()
Frm_Cadastro.Show
End Sub
Private Sub CBt_Finalizar_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If MsgBox("Confirma a finalizao do sistema?", vbYesNo + vbQuestion,
"Confirmao") = vbYes Then
ActiveWorkbook.Save
Application.Quit
Application.Visible = True
Else
Cancel = 1
End If
End Sub
Frm_Cadastro
Option Explicit
'RA = REGISTRO ATUAL
'NR = NUMERO TOTAL DE REGISTROS
'OP = OPERAO
Dim RA As Integer, NR As Integer, OP As String
Private Sub CBt_backup_Click()
ActiveWorkbook.SaveCopyAs (TBx_caminho.Text)
TBx_caminho = ""
TBx_caminho.SetFocus
End Sub
Private Sub UserForm_Activate()
LControle
Atribuir
CBx_Tipo.AddItem "Corda"
CBx_Tipo.AddItem "Sopro"
CBx_Tipo.AddItem "Percusso"
End Sub
CBx_Tipo = Sheets("Dados").Cells(Linha, 3)
TBx_Marca = Sheets("Dados").Cells(Linha, 4)
TBx_Preco = Sheets("Dados").Cells(Linha, 5)
TBx_Quantidade = Sheets("Dados").Cells(Linha, 6)
TBx_Observacoes = Sheets("Dados").Cells(Linha, 7)
Lbl_Operacao = OP & "..."
Lbl_Apontador = RA & " / " & NR
Operacao
Navegacao
End Sub
Private Sub Navegacao()
CBt_Primeiro.Enabled = (RA > 1 And OP = "Navegando")
CBt_Anterior.Enabled = (RA > 1 And OP = "Navegando")
CBt_Proximo.Enabled = (RA < NR And OP = "Navegando")
CBt_Ultimo.Enabled = (RA <> NR And OP = "Navegando")
End Sub
Private Sub Operacao()
CBt_Incluir.Enabled = (OP = "Navegando")
CBt_Alterar.Enabled = (OP = "Navegando" And RA > 0)
CBt_Excluir.Enabled = (OP = "Navegando" And RA > 0)
CBt_Cancelar.Enabled = (OP = "Incluindo" Or OP = "Alterando")
CBt_Consultar.Enabled = (OP = "Navegando" And NR > 1)
CBt_Gravar.Enabled = (OP = "Incluindo" Or OP = "Alterando")
CBt_Sair.Enabled = (OP = "Navegando")
CBt_Imprimir.Enabled = (OP = "Navegando")
End Sub
Private Sub CBt_Incluir_Click()
OP = "Incluindo"
GControle
RA = NR + 1
Atribuir
Fra_Dados.Enabled = True
TBx_Codigo.SetFocus
End Sub
Private Sub CBt_Alterar_Click()
OP = "Alterando"
GControle
Atribuir
Fra_Dados.Enabled = True
TBx_Codigo.SetFocus
End Sub