quarta-feira, 23 de fevereiro de 2011

ficha de trabalho 27

Private Sub Bloquear_Formulario()
    Text1.Enabled = False
    Text2.Enabled = False
    Text3.Enabled = False
    Text4.Enabled = False
End Sub
Private Sub Desbloquear_Formulario()
    Text1.Enabled = True
    Text2.Enabled = True
    Text3.Enabled = True
    Text4.Enabled = True
End Sub
Private Sub Command1_Click()
If Command1.Caption = "Adicionar" Then
          Data1.Recordset.AddNew
          Desbloquear_Formulario
          Text1.SetFocus
          Command3.Enabled = False
          Command2.Enabled = True
          Command1.Caption = "Cancelar"
     Else
          Data1.Recordset.CancelUpdate
          Bloquear_Formulario
          Command3.Enabled = True
          Command2.Enabled = False
          Command1.Caption = "Adicionar"
     End If
End Sub

Private Sub Command2_Click()
 If IsNumeric(Text1.Text) = False Then
        MsgBox "Inseriu letras em vez de valores numericos por favor corrija.", vbOKOnly + vbCritical, "AVISO"
       
ElseIf IsNumeric(Text2.Text) = True Then
    MsgBox "Inseriu valores numericos em vez de letras por favor corrija.", vbOKOnly + vbCritical, "AVISO"
   
    ElseIf IsNumeric(Text3.Text) = False Then
    MsgBox "Inseriu letras em vez de valores numericos por favor corrija.", vbOKOnly + vbCritical, "AVISO"
   
    ElseIf IsNumeric(Text4.Text) = False Then
    MsgBox "Inseriu letras em vez de valores numericos por favor corrija.", vbOKOnly + vbCritical, "AVISO"
   
    ElseIf IsNumeric(Text1.Text) = True And IsNumeric(Text2.Text) = False And IsNumeric(Text3.Text) = True And IsNumeric(Text4.Text) = True Then
    MsgBox "Deseja guardar os novos dados?", vbYesNo + vbQuestion, "Question"
         
          Data1.Recordset.Update
          Bloquear_Formulario
          Command3.Enabled = True
          Command2.Enabled = False
          Command1.Caption = "Adicionar"
      
       
     End If
End Sub

Private Sub Command3_Click()
     If MsgBox("Deseja eliminar este registo?", vbYesNo + vbQuestion, "Question") = vbNo Then
          MsgBox "Registo não eliminado!"
          Else
          Data1.Recordset.Delete
          MsgBox "Registo Eliminado."
          Data1.Recordset.MoveNext
          If Data1.Recordset.EOF Then
               Data1.Recordset.MovePrevious
                If Data1.Recordset.BOF Then
                    MsgBox "Não há registos!"
                    Command3.Enabled = False
                    Command4.Enabled = False
                    Command5.Enabled = False
                    Command6.Enabled = False
                    Command7.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


Sem comentários:

Enviar um comentário