Modificar Access VB6
Hola, de nuevo tengo un problemita, lo que sucede es que ya tengo todos los botones para crear y eliminar, y me hace falta el de modificar pero no me funciona, y tembien nesecito crear un filtro con dos ComboBox para que los datos se muestren en un datagrid.
Espero que me pueda colaborar, Muchicimas Gracias.
Espero que me pueda colaborar, Muchicimas Gracias.
1 respuesta
Respuesta de Roberto Alvarado
1
1
Roberto Alvarado, Desarrollador de aplicaciones en plataforma
En Guardar, falta .Update() antes del EndWith pues si no lo haces los datos no se graban en la base de datos.
Aqui dejo el codigo que se me habia olvidado.
Private Con As New Connection
Private Rec As ADODB.Recordset
Private Rec2 As ADODB.Recordset
Public var As String
Dim addFlag As Boolean
Private Sub cmdBorrar_Click()
Dim msg As Integer
msg = MsgBox("DESEA ELIMINAR EL REGISTRO?", vbYesNo, "Message")
If msg = vbNo Then Exit Sub
With Rec
.Delete
.MovePrevious
If .EOF Then .MoveLast
If .BOF Then .MoveFirst
End With
Display
End Sub
Private Sub cmdCancelar_Click()
If Rec.EOF Then
txtValor.Text = ""
txtDirigido.Text = ""
cboObra.Text = ""
DTPicker1.Value = ""
optCheque.Value = False
optEfectivo.Value = False
optConsignacion.Value = False
optTransferencia.Value = False
addFlag = True
cmdCancelar.Enabled = False
cmdGuardar.Enabled = False
cmdFirst.Enabled = True
cmdPrevious.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
Else
Rec.CancelUpdate
cmdCancelar.Enabled = False
cmdGuardar.Enabled = False
cmdFirst.Enabled = True
cmdPrevious.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
End If
Display
End Sub
Private Sub cmdFirst_Click()
Rec.MoveFirst
Display
End Sub
Private Sub cmdGuardar_Click()
With Rec
If addFlag Then .AddNew
Rec!NOMBRE = lblNombre.Caption
Rec!VALORANTICIPO = txtValor.Text
Rec!ANTICIPODIRIGIDOA = txtDirigido.Text
Rec!obra = cboObra.Text
Rec!FECHA = DTPicker1.Value
If optCheque.Value = True Then
Rec!TIPOANTICIPO = "CHEQUE"
Rec!NOCHEQUE = txtCheque.Text
Rec!NOEGRESO = txtEgreso.Text
ElseIf optEfectivo.Value = True Then
Rec!TIPOANTICIPO = "EFECTIVO"
ElseIf optConsignacion.Value = True Then
Rec!TIPOANTICIPO = "CONSIGNACION"
Else
Rec!TIPOANTICIPO = "TRANSFERENCIA"
End If
End With
If optCheque.Value = False And optEfectivo.Value = False And optConsignacion.Value = False And optTransferencia.Value = False Then
MsgBox "DEBE SELECCIONAR UN TIPO DE ANTICIPO"
End If
cmdGuardar.Enabled = False
cmdFirst.Enabled = True
cmdPrevious.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
End Sub
Private Sub cmdLast_Click()
Rec.MoveLast
Display
End Sub
Private Sub cmdModificar_Click()
Rec.Update
End Sub
Private Sub cmdNext_Click()
With Rec
.MoveNext
If .EOF Then .MoveLast
End With
Display
End Sub
Private Sub cmdNuevo_Click()
Label1.Caption = ""
txtValor.Text = ""
txtDirigido.Text = ""
Do While Rec2.EOF = False
cboObra.AddItem Rec2(1).Value
Rec2.MoveNext
Loop
DTPicker1.Value = Now
optCheque.Value = False
txtCheque.Text = ""
txtEgreso.Text = ""
optEfectivo.Value = False
optConsignacion.Value = False
optTransferencia.Value = False
addFlag = True
cmdGuardar.Enabled = True
cmdCancelar.Enabled = True
cmdFirst.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
cmdLast.Enabled = False
End Sub
Private Sub cmdPrevious_Click()
With Rec
.MovePrevious
If .BOF Then .MoveFirst
End With
Display
End Sub
Private Sub Combo1_Click()
Set Con = New ADODB.Connection
With Con
.ConnectionString = "provider = microsoft.ace.oledb.12.0;data source=D:\PROYECTO TYT\TYT.accdb"
.Open
End With
Set Rec = New ADODB.Recordset
With Rec
Set .ActiveConnection = Con
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Source = "select * from ANTICIPOS where ANTICIPODIRIGIDOA ='" & Combo1 & "'"
.Open
End With
Set DataGrid1.DataSource = Rec
End Sub
Private Sub Combo2_Change()
Set Con = New ADODB.Connection
With Con
.ConnectionString = "provider = microsoft.ace.oledb.12.0;data source=D:\PROYECTO TYT\TYT.accdb"
.Open
End With
Set Rec = New ADODB.Recordset
With Rec
Set .ActiveConnection = Con
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Source = "select * from ANTICIPOS where OBRA ='" & Combo2 & "'"
.Open
End With
Set DataGrid1.DataSource = Rec
End Sub
Private Sub Form_Activate()
Display
End Sub
Private Sub Form_Load()
'txtValor.Text = Val(Format(txtValor.Text, "##.##"))
Dim permiso As String
lblNombre = var
permiso = frmINGRESO.acc
If permiso = "A" Then
cmdNuevo.Enabled = True
cmdModificar.Enabled = True
cmdCancelar.Enabled = True
cmdGuardar.Enabled = True
cmdBorrar.Enabled = True
ElseIf permiso = "B" Then
cmdNuevo.Enabled = True
cmdModificar.Enabled = True
cmdCancelar.Enabled = True
cmdGuardar.Enabled = True
cmdBorrar.Enabled = False
Else
cmdNuevo.Enabled = True
cmdModificar.Enabled = False
cmdCancelar.Enabled = True
cmdGuardar.Enabled = True
cmdBorrar.Enabled = False
End If
Set Con = New ADODB.Connection
With Con
.ConnectionString = "provider = microsoft.ace.oledb.12.0;data source=D:\PROYECTO TYT\TYT.accdb"
.Open
End With
Set Rec = New ADODB.Recordset
Rec.Open "ANTICIPOS", Con, adOpenDynamic, adLockOptimistic, adCmdTable
addFlag = False
Set Rec2 = New ADODB.Recordset
Rec2.Open "OBRA", Con, adOpenDynamic, adLockOptimistic, adCmdTable
addFlag = False
cmdGuardar.Enabled = False
cmdCancelar.Enabled = False
End Sub
Private Sub optCheque_Click()
If optCheque.Value = True Then
lblCheque.Visible = True
txtCheque.Visible = True
lblEgreso.Visible = True
txtEgreso.Visible = True
Else
lblCheque.Visible = False
txtCheque.Visible = False
lblEgreso.Visible = False
txtEgreso.Visible = False
End If
End Sub
Private Sub optConsignacion_Click()
If optConsignacion.Value = True Then
lblCheque.Visible = False
txtCheque.Visible = False
lblEgreso.Visible = False
txtEgreso.Visible = False
Else
lblCheque.Visible = True
txtCheque.Visible = True
lblEgreso.Visible = True
txtEgreso.Visible = True
End If
End Sub
Private Sub optEfectivo_Click()
If optEfectivo.Value = True Then
lblCheque.Visible = False
txtCheque.Visible = False
lblEgreso.Visible = False
txtEgreso.Visible = False
Else
lblCheque.Visible = True
txtCheque.Visible = True
lblEgreso.Visible = True
txtEgreso.Visible = True
End If
End Sub
Private Sub optTransferencia_Click()
If optTransferencia.Value = True Then
lblCheque.Visible = False
txtCheque.Visible = False
lblEgreso.Visible = False
txtEgreso.Visible = False
Else
lblCheque.Visible = True
txtCheque.Visible = True
lblEgreso.Visible = True
txtEgreso.Visible = True
End If
End Sub
Public Sub Display()
Dim obra As String
obra = cboObra.Text
If Rec.EOF Then
txtValor.Text = ""
txtDirigido.Text = ""
cboObra.Text = ""
DTPicker1.Value = ""
optCheque.Value = False
optEfectivo.Value = False
optConsignacion.Value = False
optTransferencia.Value = False
addFlag = True
cmdBorrar.Enabled = False
Else
Label1.Caption = Rec!NO
txtValor.Text = FormatCurrency(Rec!VALORANTICIPO)
txtDirigido.Text = Rec!ANTICIPODIRIGIDOA
cboObra.Text = Rec!obra
DTPicker1.Value = Rec!FECHA
If Rec!TIPOANTICIPO = "CHEQUE" Then
optCheque.Value = True
txtCheque.Text = Rec!NOCHEQUE
txtEgreso.Text = Rec!NOEGRESO
ElseIf Rec!TIPOANTICIPO = "EFECTIVO" Then
optEfectivo.Value = True
ElseIf Rec!TIPOANTICIPO = "CONSIGNACION" Then
optConsignacion.Value = True
Else
optTransferencia.Value = True
End If
'Do While Rec.EOF = False
' Combo1.AddItem Rec2(1).Value
' Combo2.AddItem Rec(4).Value
' Rec.MoveNext
'Loop
End If
'If Rec2.EOF Then
' cboObra.Text = ""
'Else
End Sub
Private Sub Form_Unload(Cancel As Integer)
Con.Close
End Sub
Private Sub txtValor_Validate(Cancel As Boolean)
txtValor.Text = FormatCurrency(txtValor.Text)
End Sub
Private Con As New Connection
Private Rec As ADODB.Recordset
Private Rec2 As ADODB.Recordset
Public var As String
Dim addFlag As Boolean
Private Sub cmdBorrar_Click()
Dim msg As Integer
msg = MsgBox("DESEA ELIMINAR EL REGISTRO?", vbYesNo, "Message")
If msg = vbNo Then Exit Sub
With Rec
.Delete
.MovePrevious
If .EOF Then .MoveLast
If .BOF Then .MoveFirst
End With
Display
End Sub
Private Sub cmdCancelar_Click()
If Rec.EOF Then
txtValor.Text = ""
txtDirigido.Text = ""
cboObra.Text = ""
DTPicker1.Value = ""
optCheque.Value = False
optEfectivo.Value = False
optConsignacion.Value = False
optTransferencia.Value = False
addFlag = True
cmdCancelar.Enabled = False
cmdGuardar.Enabled = False
cmdFirst.Enabled = True
cmdPrevious.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
Else
Rec.CancelUpdate
cmdCancelar.Enabled = False
cmdGuardar.Enabled = False
cmdFirst.Enabled = True
cmdPrevious.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
End If
Display
End Sub
Private Sub cmdFirst_Click()
Rec.MoveFirst
Display
End Sub
Private Sub cmdGuardar_Click()
With Rec
If addFlag Then .AddNew
Rec!NOMBRE = lblNombre.Caption
Rec!VALORANTICIPO = txtValor.Text
Rec!ANTICIPODIRIGIDOA = txtDirigido.Text
Rec!obra = cboObra.Text
Rec!FECHA = DTPicker1.Value
If optCheque.Value = True Then
Rec!TIPOANTICIPO = "CHEQUE"
Rec!NOCHEQUE = txtCheque.Text
Rec!NOEGRESO = txtEgreso.Text
ElseIf optEfectivo.Value = True Then
Rec!TIPOANTICIPO = "EFECTIVO"
ElseIf optConsignacion.Value = True Then
Rec!TIPOANTICIPO = "CONSIGNACION"
Else
Rec!TIPOANTICIPO = "TRANSFERENCIA"
End If
End With
If optCheque.Value = False And optEfectivo.Value = False And optConsignacion.Value = False And optTransferencia.Value = False Then
MsgBox "DEBE SELECCIONAR UN TIPO DE ANTICIPO"
End If
cmdGuardar.Enabled = False
cmdFirst.Enabled = True
cmdPrevious.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
End Sub
Private Sub cmdLast_Click()
Rec.MoveLast
Display
End Sub
Private Sub cmdModificar_Click()
Rec.Update
End Sub
Private Sub cmdNext_Click()
With Rec
.MoveNext
If .EOF Then .MoveLast
End With
Display
End Sub
Private Sub cmdNuevo_Click()
Label1.Caption = ""
txtValor.Text = ""
txtDirigido.Text = ""
Do While Rec2.EOF = False
cboObra.AddItem Rec2(1).Value
Rec2.MoveNext
Loop
DTPicker1.Value = Now
optCheque.Value = False
txtCheque.Text = ""
txtEgreso.Text = ""
optEfectivo.Value = False
optConsignacion.Value = False
optTransferencia.Value = False
addFlag = True
cmdGuardar.Enabled = True
cmdCancelar.Enabled = True
cmdFirst.Enabled = False
cmdPrevious.Enabled = False
cmdNext.Enabled = False
cmdLast.Enabled = False
End Sub
Private Sub cmdPrevious_Click()
With Rec
.MovePrevious
If .BOF Then .MoveFirst
End With
Display
End Sub
Private Sub Combo1_Click()
Set Con = New ADODB.Connection
With Con
.ConnectionString = "provider = microsoft.ace.oledb.12.0;data source=D:\PROYECTO TYT\TYT.accdb"
.Open
End With
Set Rec = New ADODB.Recordset
With Rec
Set .ActiveConnection = Con
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Source = "select * from ANTICIPOS where ANTICIPODIRIGIDOA ='" & Combo1 & "'"
.Open
End With
Set DataGrid1.DataSource = Rec
End Sub
Private Sub Combo2_Change()
Set Con = New ADODB.Connection
With Con
.ConnectionString = "provider = microsoft.ace.oledb.12.0;data source=D:\PROYECTO TYT\TYT.accdb"
.Open
End With
Set Rec = New ADODB.Recordset
With Rec
Set .ActiveConnection = Con
.CursorType = adOpenDynamic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Source = "select * from ANTICIPOS where OBRA ='" & Combo2 & "'"
.Open
End With
Set DataGrid1.DataSource = Rec
End Sub
Private Sub Form_Activate()
Display
End Sub
Private Sub Form_Load()
'txtValor.Text = Val(Format(txtValor.Text, "##.##"))
Dim permiso As String
lblNombre = var
permiso = frmINGRESO.acc
If permiso = "A" Then
cmdNuevo.Enabled = True
cmdModificar.Enabled = True
cmdCancelar.Enabled = True
cmdGuardar.Enabled = True
cmdBorrar.Enabled = True
ElseIf permiso = "B" Then
cmdNuevo.Enabled = True
cmdModificar.Enabled = True
cmdCancelar.Enabled = True
cmdGuardar.Enabled = True
cmdBorrar.Enabled = False
Else
cmdNuevo.Enabled = True
cmdModificar.Enabled = False
cmdCancelar.Enabled = True
cmdGuardar.Enabled = True
cmdBorrar.Enabled = False
End If
Set Con = New ADODB.Connection
With Con
.ConnectionString = "provider = microsoft.ace.oledb.12.0;data source=D:\PROYECTO TYT\TYT.accdb"
.Open
End With
Set Rec = New ADODB.Recordset
Rec.Open "ANTICIPOS", Con, adOpenDynamic, adLockOptimistic, adCmdTable
addFlag = False
Set Rec2 = New ADODB.Recordset
Rec2.Open "OBRA", Con, adOpenDynamic, adLockOptimistic, adCmdTable
addFlag = False
cmdGuardar.Enabled = False
cmdCancelar.Enabled = False
End Sub
Private Sub optCheque_Click()
If optCheque.Value = True Then
lblCheque.Visible = True
txtCheque.Visible = True
lblEgreso.Visible = True
txtEgreso.Visible = True
Else
lblCheque.Visible = False
txtCheque.Visible = False
lblEgreso.Visible = False
txtEgreso.Visible = False
End If
End Sub
Private Sub optConsignacion_Click()
If optConsignacion.Value = True Then
lblCheque.Visible = False
txtCheque.Visible = False
lblEgreso.Visible = False
txtEgreso.Visible = False
Else
lblCheque.Visible = True
txtCheque.Visible = True
lblEgreso.Visible = True
txtEgreso.Visible = True
End If
End Sub
Private Sub optEfectivo_Click()
If optEfectivo.Value = True Then
lblCheque.Visible = False
txtCheque.Visible = False
lblEgreso.Visible = False
txtEgreso.Visible = False
Else
lblCheque.Visible = True
txtCheque.Visible = True
lblEgreso.Visible = True
txtEgreso.Visible = True
End If
End Sub
Private Sub optTransferencia_Click()
If optTransferencia.Value = True Then
lblCheque.Visible = False
txtCheque.Visible = False
lblEgreso.Visible = False
txtEgreso.Visible = False
Else
lblCheque.Visible = True
txtCheque.Visible = True
lblEgreso.Visible = True
txtEgreso.Visible = True
End If
End Sub
Public Sub Display()
Dim obra As String
obra = cboObra.Text
If Rec.EOF Then
txtValor.Text = ""
txtDirigido.Text = ""
cboObra.Text = ""
DTPicker1.Value = ""
optCheque.Value = False
optEfectivo.Value = False
optConsignacion.Value = False
optTransferencia.Value = False
addFlag = True
cmdBorrar.Enabled = False
Else
Label1.Caption = Rec!NO
txtValor.Text = FormatCurrency(Rec!VALORANTICIPO)
txtDirigido.Text = Rec!ANTICIPODIRIGIDOA
cboObra.Text = Rec!obra
DTPicker1.Value = Rec!FECHA
If Rec!TIPOANTICIPO = "CHEQUE" Then
optCheque.Value = True
txtCheque.Text = Rec!NOCHEQUE
txtEgreso.Text = Rec!NOEGRESO
ElseIf Rec!TIPOANTICIPO = "EFECTIVO" Then
optEfectivo.Value = True
ElseIf Rec!TIPOANTICIPO = "CONSIGNACION" Then
optConsignacion.Value = True
Else
optTransferencia.Value = True
End If
'Do While Rec.EOF = False
' Combo1.AddItem Rec2(1).Value
' Combo2.AddItem Rec(4).Value
' Rec.MoveNext
'Loop
End If
'If Rec2.EOF Then
' cboObra.Text = ""
'Else
End Sub
Private Sub Form_Unload(Cancel As Integer)
Con.Close
End Sub
Private Sub txtValor_Validate(Cancel As Boolean)
txtValor.Text = FormatCurrency(txtValor.Text)
End Sub
- Compartir respuesta
- Anónimo
ahora mismo