1.
Código:
Private Sub Command1_Click()
If Command1.Caption = "Novo" Then
Data1.Recordset.AddNew
Desbloquear
Limpar
Text1.SetFocus
Command2.Enabled = False
Command4.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
Command10.Enabled = False
Command12.Enabled = False
Command1.Caption = "Cancelar"
Else
Data1.Recordset.CancelUpdate
Bloquear
Command2.Enabled = True
Command4.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Command10.Enabled = True
Command12.Enabled = True
Command1.Caption = "Novo"
End If
End Sub
Private Sub Command10_Click()
Data1.Recordset.MoveLast
End Sub
Private Sub Command11_Click()
Form2.Show
End Sub
Private Sub Command12_Click()
MsgBox "Registo eliminado!", vbInformation, "Eliminado"
Data1.Recordset.Delete
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
MsgBox "Não há registos!", vbCritical, "Aviso"
Command12.Enabled = False
End If
End If
End Sub
Private Sub Command2_Click()
If Command2.Caption = "Editar" Then
Desbloquear
Data1.Recordset.Edit
Command1.Enabled = False
Command12.Enabled = False
Command4.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
Command10.Enabled = False
Command2.Caption = "Cancelar"
Else
Data1.Recordset.CancelUpdate
Bloquear
Command1.Enabled = True
Command12.Enabled = True
Command4.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Command10.Enabled = True
Command2.Caption = "Editar"
End If
End Sub
Private Sub Command4_Click()
Dim p As String
p = UCase(InputBox("Introduza o nome que quer pesquisar", "Pesquisar"))
If Trim(p) <> "" Then
Data1.Recordset.FindFirst "nome='" & p & "'"
If Data1.Recordset.NoMatch = True Then
MsgBox "Não existe esse registo", vbCritical, "Aviso"
Data1.Recordset.MoveFirst
End If
End If
End Sub
Private Sub Command5_Click()
If MsgBox("Deseja sair?", vbQuestion + vbYesNo, "Sair") = vbYes Then
End
End If
End Sub
Private Sub Command6_Click()
If Text1.Text = "" Then
MsgBox "Preencha o campo do número", vbCritical, "1º campo"
Text1.SetFocus
ElseIf Text2.Text = "" Then
MsgBox "Preencha o campo do nome", vbCritical, "2º campo"
Text2.SetFocus
ElseIf Text3.Text = "" Then
MsgBox "Preencha o campo da morada", vbCritical, "3º campo"
Text3.SetFocus
ElseIf Text4.Text = "" Then
MsgBox "Preencha o campo do telefone", vbCritical, "4º campo"
Text4.SetFocus
ElseIf Text5.Text = "" Then
MsgBox "Preencha o campo do código postal", vbCritical, "5º campo"
Text5.SetFocus
ElseIf Text6.Text = "" Then
MsgBox "Preencha o campo da localidade", vbCritical, "6º campo"
Text6.SetFocus
Else
MsgBox "Os dados foram guardados!", vbInformation, "Informação"
Data1.Recordset.Update
Bloquear
Command1.Enabled = True
Command2.Enabled = True
Command4.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Command10.Enabled = True
Command12.Enabled = True
Command1.Caption = "Novo"
Command2.Caption = "Editar"
End If
End Sub
Private Sub Command7_Click()
Data1.Recordset.MoveFirst
End Sub
Private Sub Command8_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub Command9_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End Sub
Private Sub Form_Load()
Bloquear
End Sub
Private Sub Timer1_Timer()
Label6.Caption = Time()
Label7.Caption = Date
End Sub
Private Sub Bloquear()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
End Sub
Private Sub Desbloquear()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text6.Enabled = True
End Sub
Private Sub Limpar()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub
If Command1.Caption = "Novo" Then
Data1.Recordset.AddNew
Desbloquear
Limpar
Text1.SetFocus
Command2.Enabled = False
Command4.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
Command10.Enabled = False
Command12.Enabled = False
Command1.Caption = "Cancelar"
Else
Data1.Recordset.CancelUpdate
Bloquear
Command2.Enabled = True
Command4.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Command10.Enabled = True
Command12.Enabled = True
Command1.Caption = "Novo"
End If
End Sub
Private Sub Command10_Click()
Data1.Recordset.MoveLast
End Sub
Private Sub Command11_Click()
Form2.Show
End Sub
Private Sub Command12_Click()
MsgBox "Registo eliminado!", vbInformation, "Eliminado"
Data1.Recordset.Delete
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
MsgBox "Não há registos!", vbCritical, "Aviso"
Command12.Enabled = False
End If
End If
End Sub
Private Sub Command2_Click()
If Command2.Caption = "Editar" Then
Desbloquear
Data1.Recordset.Edit
Command1.Enabled = False
Command12.Enabled = False
Command4.Enabled = False
Command7.Enabled = False
Command8.Enabled = False
Command9.Enabled = False
Command10.Enabled = False
Command2.Caption = "Cancelar"
Else
Data1.Recordset.CancelUpdate
Bloquear
Command1.Enabled = True
Command12.Enabled = True
Command4.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Command10.Enabled = True
Command2.Caption = "Editar"
End If
End Sub
Private Sub Command4_Click()
Dim p As String
p = UCase(InputBox("Introduza o nome que quer pesquisar", "Pesquisar"))
If Trim(p) <> "" Then
Data1.Recordset.FindFirst "nome='" & p & "'"
If Data1.Recordset.NoMatch = True Then
MsgBox "Não existe esse registo", vbCritical, "Aviso"
Data1.Recordset.MoveFirst
End If
End If
End Sub
Private Sub Command5_Click()
If MsgBox("Deseja sair?", vbQuestion + vbYesNo, "Sair") = vbYes Then
End
End If
End Sub
Private Sub Command6_Click()
If Text1.Text = "" Then
MsgBox "Preencha o campo do número", vbCritical, "1º campo"
Text1.SetFocus
ElseIf Text2.Text = "" Then
MsgBox "Preencha o campo do nome", vbCritical, "2º campo"
Text2.SetFocus
ElseIf Text3.Text = "" Then
MsgBox "Preencha o campo da morada", vbCritical, "3º campo"
Text3.SetFocus
ElseIf Text4.Text = "" Then
MsgBox "Preencha o campo do telefone", vbCritical, "4º campo"
Text4.SetFocus
ElseIf Text5.Text = "" Then
MsgBox "Preencha o campo do código postal", vbCritical, "5º campo"
Text5.SetFocus
ElseIf Text6.Text = "" Then
MsgBox "Preencha o campo da localidade", vbCritical, "6º campo"
Text6.SetFocus
Else
MsgBox "Os dados foram guardados!", vbInformation, "Informação"
Data1.Recordset.Update
Bloquear
Command1.Enabled = True
Command2.Enabled = True
Command4.Enabled = True
Command7.Enabled = True
Command8.Enabled = True
Command9.Enabled = True
Command10.Enabled = True
Command12.Enabled = True
Command1.Caption = "Novo"
Command2.Caption = "Editar"
End If
End Sub
Private Sub Command7_Click()
Data1.Recordset.MoveFirst
End Sub
Private Sub Command8_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub Command9_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End Sub
Private Sub Form_Load()
Bloquear
End Sub
Private Sub Timer1_Timer()
Label6.Caption = Time()
Label7.Caption = Date
End Sub
Private Sub Bloquear()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
End Sub
Private Sub Desbloquear()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text6.Enabled = True
End Sub
Private Sub Limpar()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub
Sem comentários:
Enviar um comentário