1.
Código:
rivate Sub Command1_Click()
If Command1.Caption = "Adicionar" Then
Data1.Recordset.AddNew
Desbloquear
Text1.SetFocus
Command3.Enabled = False
Command2.Enabled = True
Command1.Caption = "Cancelar"
Else
Data1.Recordset.CancelUpdate
Bloquear
Command3.Enabled = True
Command2.Enabled = False
Command1.Caption = "Adicionar"
End If
End Sub
Private Sub Command2_Click()
If MsgBox("Deseja Guardar?", vbYesNo + vbQuestion, "Questão") = vbYes Then
If Text1.Text = "" Then
MsgBox "Preencha o primeiro campo", vbCritical, "Aviso"
Text1.SetFocus
ElseIf Text2.Text = "" Then
MsgBox "Preencha o segundo campo", vbCritical, "Aviso"
Text2.SetFocus
ElseIf Text3.Text < 0 Or Text3.Text > 20 Then
MsgBox "Nota inválida do primeiro trabalho", vbCritical, "Aviso"
Text3.SetFocus
ElseIf Text4.Text < 0 Or Text4.Text > 20 Then
MsgBox "Nota inválida do primeiro trabalho", vbCritical, "Aviso"
Text4.SetFocus
Else
Data1.Recordset.Update
Bloquear
Command2.Enabled = False
Command3.Enabled = True
Command1.Caption = "Adicionar"
End If
End If
End Sub
Private Sub Command3_Click()
If MsgBox("Deseja eliminar?", vbYesNo + vbQuestion, "Questão") = vbNo Then
MsgBox "Registo não eliminado!", vbInformation, "Informação"
Else
Data1.Recordset.Delete
MsgBox "Registo eliminado!", vbInformation, "Informação"
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
MsgBox "Não há registos", vbInformation, "Informação"
Command3.Enabled = False
End If
End If
End If
End Sub
Private Sub Command4_Click()
Data1.Recordset.MoveFirst
End Sub
Private Sub Command5_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub Command6_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End Sub
Private Sub Command7_Click()
Data1.Recordset.MoveLast
End Sub
Private Sub Bloquear()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
End Sub
Private Sub Desbloquear()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
End Sub
Private Sub Form_Load()
Bloquear
Command2.Enabled = False
End Sub
If Command1.Caption = "Adicionar" Then
Data1.Recordset.AddNew
Desbloquear
Text1.SetFocus
Command3.Enabled = False
Command2.Enabled = True
Command1.Caption = "Cancelar"
Else
Data1.Recordset.CancelUpdate
Bloquear
Command3.Enabled = True
Command2.Enabled = False
Command1.Caption = "Adicionar"
End If
End Sub
Private Sub Command2_Click()
If MsgBox("Deseja Guardar?", vbYesNo + vbQuestion, "Questão") = vbYes Then
If Text1.Text = "" Then
MsgBox "Preencha o primeiro campo", vbCritical, "Aviso"
Text1.SetFocus
ElseIf Text2.Text = "" Then
MsgBox "Preencha o segundo campo", vbCritical, "Aviso"
Text2.SetFocus
ElseIf Text3.Text < 0 Or Text3.Text > 20 Then
MsgBox "Nota inválida do primeiro trabalho", vbCritical, "Aviso"
Text3.SetFocus
ElseIf Text4.Text < 0 Or Text4.Text > 20 Then
MsgBox "Nota inválida do primeiro trabalho", vbCritical, "Aviso"
Text4.SetFocus
Else
Data1.Recordset.Update
Bloquear
Command2.Enabled = False
Command3.Enabled = True
Command1.Caption = "Adicionar"
End If
End If
End Sub
Private Sub Command3_Click()
If MsgBox("Deseja eliminar?", vbYesNo + vbQuestion, "Questão") = vbNo Then
MsgBox "Registo não eliminado!", vbInformation, "Informação"
Else
Data1.Recordset.Delete
MsgBox "Registo eliminado!", vbInformation, "Informação"
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
MsgBox "Não há registos", vbInformation, "Informação"
Command3.Enabled = False
End If
End If
End If
End Sub
Private Sub Command4_Click()
Data1.Recordset.MoveFirst
End Sub
Private Sub Command5_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub Command6_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End Sub
Private Sub Command7_Click()
Data1.Recordset.MoveLast
End Sub
Private Sub Bloquear()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
End Sub
Private Sub Desbloquear()
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
End Sub
Private Sub Form_Load()
Bloquear
Command2.Enabled = False
End Sub
Sem comentários:
Enviar um comentário