quarta-feira, 17 de fevereiro de 2010

Ficha 22 - Em base de Dados







Private Sub Sair_Click()

If MsgBox("Deseja sair?", vbYesNo + vbQuestion, " Aviso") = vbYes Then End

End Sub

Private Sub cmdPrimeiro_Click()
If Data1.Recordset.BOF Then
MsgBox " Base de dados vazia"
Else
Data1.Recordset.MoveFirst
End If

End Sub
Private Sub cmdSeguinte_Click()

If Data1.Recordset.EOF Then
If Data1.Recordset.BOF Then
MsgBox "Base de Dados vazia!"
End If
Else
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End If

End Sub
Private Sub cmdAnterior_Click()

If Data1.Recordset.BOF Then
If Data1.Recordset.EOF Then
MsgBox "Base de Dados vazia!"
End If
Else
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
End If
End If

End Sub
Private Sub cmdUltimo_Click()
If Data1.Recordset.EOF Then
MsgBox " Base de dados vazia"
Else
Data1.Recordset.MoveLast
End If

End Sub

Private Sub Form_Load()

cmdGuardar.Enabled = False

End Sub
Private Sub cmdAdicionar_Click()

If cmdAdicionar.Caption = "Adicionar" Then
Data1.Recordset.AddNew
txtcodigo.SetFocus
txtfuncionario.SetFocus
txtsalario.SetFocus
txtvale.SetFocus


cmdEliminar.Enabled = False
cmdGuardar.Enabled = True
cmdAdicionar.Caption = "Cancelar"
Else

cmdEliminar.Enabled = True
cmdGuardar.Enabled = False
cmdAdicionar.Caption = "Adicionar"
End If

End Sub
Private Sub cmdGuardar_Click()

Dim Resp As Integer, Mens As String

If txtcodigo.Text = Empty Then

MsgBox "Preencha o campo Código", vbOKOnly + vbExclamation, " Aviso"

ElseIf txtfuncionario.Text = Empty Then

MsgBox "Preencha o campo Funcionário", vbOKOnly + vbExclamation, " Aviso"

ElseIf txtsalario.Text = Empty Then

MsgBox "Preencha o campo Salário", vbOKOnly + vbExclamation, " Aviso"

ElseIf txtvale.Text = Empty Then

MsgBox "Preencha o campo Vale", vbOKOnly + vbExclamation, " Aviso"

Else
Mens = "Deseja guardar os novos dados?"
Resp = MsgBox(Mens, vbYesNo + vbQuestion, "Question")

If Resp = vbYes Then
txttotal.Text = Val(txtsalario.Text) + Val(txtvale.Text)

Data1.Recordset.Update
cmdEliminar.Enabled = True
cmdGuardar.Enabled = False
cmdAdicionar.Caption = "Adicionar"
End If
End If

End Sub
Private Sub cmdEliminar_click()

If MsgBox("Deseja eliminar este registo?", vbYesNo + vbQuestion, "Question") = vbNo Then
MsgBox "Registo não eliminado"
Else
Data1.Recordset.Delete
Data1.Recordset.MoveNext

If Data1.Recordset.EOF Then
Data1.Recordset.MovePrevious

If Data1.Recordset.BOF Then
MsgBox "Não há registos"
cmdEliminar.Enabled = False
End If

End If
MsgBox "Registo Eliminado"
End If

End Sub

Private Sub Retroceder_Click()

End Sub

Private Sub Timer1_Timer()

Hora_Data = Now

End Sub

Private Sub txtcodigo_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub

Private Sub txtfuncionario_KeyPress(KeyAscii As Integer)

Select Case KeyAscii
Case vbKeyDelete
Case vbKeyBack
Case 65 To 90
Case 97 To 122
Case 32
Case Else
Beep
KeyAscii = 0
End Select

End Sub

Private Sub txtsalario_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub

Private Sub txtvale_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub

Sem comentários:

Enviar um comentário