RUSMAN_72
21 dic 2011, 08:27
espero te sirva:
Mi ejemplo es para agregar, modificar, dar de alta libros, y cancelar las operaciones anteriores regresandote al menu.
Function VALIDAR() As Boolean
If REGISTRO.Text = "" Or ASIGNATURA.Text = "" Or TITULO.Text = "" Or AUTOR.Text = "" Or EDITORIAL.Text = "" Or BIBLIOTECA.Text = "" Or OBSERVACIONES.Text = "" Then
VALIDAR = True
MsgBox "Debe Insertar el o los Dato(s) Faltante(s)", vbInformation, "ok"
MsgBox "Este recurso no ha sido Actualizado ni Guardado", vbInformation, "ok"
Adodc1.Recordset.CancelUpdate
ALTA.Visible = False
AGREGAR.Visible = True
CANCELAR.Visible = True
ACTUALIZAR.Visible = True
AGREGAR.Enabled = True
ACTUALIZAR.Enabled = True
NPBG.Enabled = False
REGISTRO.Enabled = False
ASIGNATURA.Enabled = False
TITULO.Enabled = False
AUTOR.Enabled = False
EDITORIAL.Enabled = False
BIBLIOTECA.Enabled = False
OBSERVACIONES.Enabled = False
ALTA.Enabled = False
AGREGAR.SetFocus
End If
End Function
Function limpiar()
NPBG.Text = ""
REGISTRO.Text = ""
ASIGNATURA.Text = ""
TITULO.Text = ""
AUTOR.Text = ""
EDITORIAL.Text = ""
BIBLIOTECA.Text = ""
OBSERVACIONES.Text = ""
End Function
Private Sub ACTUALIZAR_Click()
ALTA.Visible = True
AGREGAR.Visible = False
CANCELAR.Visible = False
ACTUALIZAR.Visible = False
ALTA.Enabled = True
AGREGAR.Enabled = False
ACTUALIZAR.Enabled = False
NPBG.Enabled = False
REGISTRO.Enabled = True
ASIGNATURA.Enabled = True
TITULO.Enabled = True
AUTOR.Enabled = True
EDITORIAL.Enabled = True
BIBLIOTECA.Enabled = True
OBSERVACIONES.Enabled = True
End Sub
Private Sub AGREGAR_Click()
ALTA.Visible = True
AGREGAR.Visible = False
CANCELAR.Visible = False
ACTUALIZAR.Visible = False
ALTA.Enabled = True
ACTUALIZAR.Enabled = False
AGREGAR.Enabled = False
NPBG.Enabled = False
REGISTRO.Enabled = True
ASIGNATURA.Enabled = True
TITULO.Enabled = True
AUTOR.Enabled = True
EDITORIAL.Enabled = True
BIBLIOTECA.Enabled = True
OBSERVACIONES.Enabled = True
Adodc1.Recordset.AddNew
REGISTRO.SetFocus
End Sub
Private Sub ALTA_Click()
If VALIDAR = True Then
Exit Sub
End If
ALTA.Visible = False
AGREGAR.Visible = True
CANCELAR.Visible = True
ACTUALIZAR.Visible = True
NPBG.Enabled = False
REGISTRO.Enabled = False
ASIGNATURA.Enabled = False
TITULO.Enabled = False
AUTOR.Enabled = False
EDITORIAL.Enabled = False
BIBLIOTECA.Enabled = False
OBSERVACIONES.Enabled = False
ALTA.Enabled = False
ACTUALIZAR.Enabled = True
AGREGAR.Enabled = True
CANCELAR.Enabled = True
Adodc1.Recordset.Update
MsgBox "Recurso Actualizado y Guardado Correctamente ", vbInformation, "ok"
End Sub
Private Sub ANULACIÓN_Click()
NPBG.Enabled = False
REGISTRO.Enabled = False
ASIGNATURA.Enabled = False
TITULO.Enabled = False
AUTOR.Enabled = False
EDITORIAL.Enabled = False
BIBLIOTECA.Enabled = False
OBSERVACIONES.Enabled = False
AGREGAR.Enabled = True
ALTA.Enabled = False
ACTUALIZAR.Enabled = True
ANULACIÓN.Enabled = False
CANCELAR.Enabled = True
Adodc1.Recordset.CancelUpdate
End Sub
Private Sub ASIGNATURA_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
TITULO.SetFocus
End If
End Sub
Private Sub AUTOR_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
EDITORIAL.SetFocus
End If
End Sub
Private Sub BIBLIOTECA_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
OBSERVACIONES.SetFocus
End If
End Sub
Private Sub CANCELAR_Click()
Form3.Visible = True
Form4.Visible = False
NPBG.Enabled = False
REGISTRO.Enabled = False
ASIGNATURA.Enabled = False
TITULO.Enabled = False
AUTOR.Enabled = False
EDITORIAL.Enabled = False
BIBLIOTECA.Enabled = False
OBSERVACIONES.Enabled = False
ALTA.Enabled = False
ACTUALIZAR.Enabled = True
CANCELAR.Enabled = True
AGREGAR.Enabled = True
End Sub
Private Sub EDITORIAL_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
BIBLIOTECA.SetFocus
End If
End Sub
Private Sub Form_Load()
Call Conectar
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 0 Then Cancel = 1
End Sub
Private Sub OBSERVACIONES_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
ALTA.SetFocus
End If
End Sub
Private Sub REGISTRO_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
ASIGNATURA.SetFocus
End If
End Sub
Private Sub Timer1_Timer()
Dim fecha As Variant
fecha = Date
Label4.Caption = Str(fecha)
End Sub
Private Sub TITULO_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
AUTOR.SetFocus
End If
End Sub
Dim rs1 As Recordset
Private Sub CmdEDITAR_Click(Index As Integer)
Dim strtitle As String
Text2.Text = UCase(Text2.Text)
If Text1.Text = "" Then
MsgBox ("Debe introducir el Codigo de la serie.")
Text1.SetFocus
ElseIf (Text2.Text = "") Then
MsgBox ("Debe introducir el Nombre de la serie.")
Text2.SetFocus
End If
strtitle = Text1.Text
rs1.FindFirst "Codserie = '" & strtitle & "'"
If rs1.NoMatch Then
rs1.Edit
End If
End Sub
Private Sub CmdPrimero_Click(Index As Integer)
rs1.MoveFirst
Text1.Text = rs1.Fields("Codserie")
Text2.Text = rs1.Fields("Nomserie")
End Sub
Private Sub CmdUltimo_Click()
rs1.MoveLast
Text1.Text = rs1.Fields("Codserie")
Text2.Text = rs1.Fields("Nomserie")
End Sub
Private Sub Form_Load()
Set db = Workspaces(0).OpenDatabase("C:\PROGRAMASERVICIO\BASE DE DATOS\servicio.mdb")
Set rs1 = db.OpenRecordset("serie", dbOpenDynaset)
End Sub
Private Sub Text1_KEYPRESS(KEYASCII As Integer)
Dim num As String
If Not (KEYASCII >= 48 And KEYASCII <= 57 Or KEYASCII = 8) Then
KEYASCII = 0
End If
num = Len(Text1.Text)
If num = 3 Then
Text2.SetFocus
End If
End Sub
Private Sub CmdGUARDAR_Click(Index As Integer)
Dim strtitle As String
Text2.Text = UCase(Text2.Text)
If Text1.Text = "" Then
MsgBox ("Debe introducir el Codigo de la serie.")
Text1.SetFocus
ElseIf (Text2.Text = "") Then
MsgBox ("Debe introducir el Nombre de la serie.")
Text2.SetFocus
End If
strtitle = Text1.Text
rs1.FindFirst "Codserie = '" & strtitle & "'"
If rs1.NoMatch Then
rs1.AddNew
rs1.Fields("Codserie") = Text1.Text
rs1.Fields("NomSerie") = Text2.Text
rs1.Update
MsgBox ("el registro fue guardado satisfactoriamente")
Else
MsgBox ("El Codigo ya Existe.")
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Cmdnuevo_Click(Index As Integer)
rs1.AddNew
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub CmdSALIR_Click(Index As Integer)
Form5.Hide
End Sub