Ayuda con error al ingresar datos en una tabla desde aplicación en visual basic
De ante mano muchas gracias a los que puedan responder mi gran duda y problema.
Tengo un ingreso de materiales a una tabla, pero cuando esta tabla esta vacía me sale el siguiente error:
Error 3021 el valor eof o bof es true
Eso lo tengo claro que el valor es true, ¿pero cómo lo puedo solucionar para nuevos registros?, les dejo el código de ingreso:
Public Function agregar()
Dim saveSQL As String
Dim C As Variant
Dim Var1 As Integer
Dim strA As String
Dim rsA As New ADODB.Recordset
Dim STOCK1 As Integer
Principal.StatusBar1.Panels.Item(2) = Me.txt_usuarios
strA = "SELECT TOP 1 * FROM TB_CONTROLFARMACOS WHERE FLD_MATCODIGO ='" & Me.txt_cod_interno & "' ORDER BY FECHA DESC "
Set rsA = ABASTECIMIENTO.Execute(strA)
'MsgBox strA
If (rsA!ESTADO <> i) Then <------------ ACA EL ERROR
STOCK1 = Val(rsA!STOCK) + Me.txt_cantidad
Else
STOCK1 = Val(rsA!STOCK) - Me.txt_cantidad
End If
'Ingreso Datos
saveSQL = "INSERT INTO TB_CONTROLFARMACOS(FLD_MATCODIGO, FECHA, "
saveSQL = saveSQL & "CANTIDAD, STOCK, USUARIO, ESTADO) "
saveSQL = saveSQL & "VALUES ("
saveSQL = saveSQL & "'" & Me.txt_cod_interno & "', "
saveSQL = saveSQL & "'" & Format(Me.dtp_fecha, "dd/mm/yyyy HH:mm") & "', "
saveSQL = saveSQL & "'" & Me.txt_cantidad & "', "
saveSQL = saveSQL & STOCK1 & ", "
saveSQL = saveSQL & "'" & Principal.StatusBar1.Panels.Item(2) & "', "
saveSQL = saveSQL & "'" & Me.txt_estado & "') "
ABASTECIMIENTO.Execute (saveSQL)
With Me.spr_ingreos
.MaxRows = .MaxRows + 1
.Col = 1
.Row = .MaxRows
.Text = Me.txt_cod_interno
.Col = 2
.Row = .MaxRows
.Text = Me.txt_nombre
.Col = 3
.Row = .MaxRows
.Text = Me.txt_cantidad
End With
limpiar
Me.txt_cod_interno.SetFocus
End Function
Public Function agregar()
Dim saveSQL As StringDim C As VariantDim Var1 As IntegerDim strA As StringDim rsA As New ADODB.RecordsetDim STOCK1 As Integer
Principal.StatusBar1.Panels.Item(2) = Me.txt_usuarios strA = "SELECT TOP 1 * FROM TB_CONTROLFARMACOS WHERE FLD_MATCODIGO ='" & Me.txt_cod_interno & "' ORDER BY FECHA DESC " Set rsA = ABASTECIMIENTO.Execute(strA) 'MsgBox strA 'On Error Resume Next ' If rsA.EOF Then' rsA!ESTADO = Me.txt_estado' End If ' If rsA.EOF Then Exit Sub If (rsA!ESTADO <> i) Then STOCK1 = Val(rsA!STOCK) + Me.txt_cantidad Else STOCK1 = Val(rsA!STOCK) - Me.txt_cantidad End If 'Ingreso Datos saveSQL = "INSERT INTO TB_CONTROLFARMACOS(FLD_MATCODIGO, FECHA, " saveSQL = saveSQL & "CANTIDAD, STOCK, USUARIO, ESTADO) " saveSQL = saveSQL & "VALUES (" saveSQL = saveSQL & "'" & Me.txt_cod_interno & "', " saveSQL = saveSQL & "'" & Format(Me.dtp_fecha, "dd/mm/yyyy HH:mm") & "', " saveSQL = saveSQL & "'" & Me.txt_cantidad & "', " saveSQL = saveSQL & STOCK1 & ", " saveSQL = saveSQL & "'" & Principal.StatusBar1.Panels.Item(2) & "', " saveSQL = saveSQL & "'" & Me.txt_estado & "') " ABASTECIMIENTO.Execute (saveSQL) With Me.spr_ingreos .MaxRows = .MaxRows + 1 .Col = 1 .Row = .MaxRows .Text = Me.txt_cod_interno .Col = 2 .Row = .MaxRows .Text = Me.txt_nombre .Col = 3 .Row = .MaxRows .Text = Me.txt_cantidad End With limpiar Me.txt_cod_interno.SetFocus
End Function
Si pongo "On Error Resume Next", me pasa el error, hace todo, pero no me graba los datos a la tabla.
Ayuda please, he buscado por todos lados.
Tengo un ingreso de materiales a una tabla, pero cuando esta tabla esta vacía me sale el siguiente error:
Error 3021 el valor eof o bof es true
Eso lo tengo claro que el valor es true, ¿pero cómo lo puedo solucionar para nuevos registros?, les dejo el código de ingreso:
Public Function agregar()
Dim saveSQL As String
Dim C As Variant
Dim Var1 As Integer
Dim strA As String
Dim rsA As New ADODB.Recordset
Dim STOCK1 As Integer
Principal.StatusBar1.Panels.Item(2) = Me.txt_usuarios
strA = "SELECT TOP 1 * FROM TB_CONTROLFARMACOS WHERE FLD_MATCODIGO ='" & Me.txt_cod_interno & "' ORDER BY FECHA DESC "
Set rsA = ABASTECIMIENTO.Execute(strA)
'MsgBox strA
If (rsA!ESTADO <> i) Then <------------ ACA EL ERROR
STOCK1 = Val(rsA!STOCK) + Me.txt_cantidad
Else
STOCK1 = Val(rsA!STOCK) - Me.txt_cantidad
End If
'Ingreso Datos
saveSQL = "INSERT INTO TB_CONTROLFARMACOS(FLD_MATCODIGO, FECHA, "
saveSQL = saveSQL & "CANTIDAD, STOCK, USUARIO, ESTADO) "
saveSQL = saveSQL & "VALUES ("
saveSQL = saveSQL & "'" & Me.txt_cod_interno & "', "
saveSQL = saveSQL & "'" & Format(Me.dtp_fecha, "dd/mm/yyyy HH:mm") & "', "
saveSQL = saveSQL & "'" & Me.txt_cantidad & "', "
saveSQL = saveSQL & STOCK1 & ", "
saveSQL = saveSQL & "'" & Principal.StatusBar1.Panels.Item(2) & "', "
saveSQL = saveSQL & "'" & Me.txt_estado & "') "
ABASTECIMIENTO.Execute (saveSQL)
With Me.spr_ingreos
.MaxRows = .MaxRows + 1
.Col = 1
.Row = .MaxRows
.Text = Me.txt_cod_interno
.Col = 2
.Row = .MaxRows
.Text = Me.txt_nombre
.Col = 3
.Row = .MaxRows
.Text = Me.txt_cantidad
End With
limpiar
Me.txt_cod_interno.SetFocus
End Function
Public Function agregar()
Dim saveSQL As StringDim C As VariantDim Var1 As IntegerDim strA As StringDim rsA As New ADODB.RecordsetDim STOCK1 As Integer
Principal.StatusBar1.Panels.Item(2) = Me.txt_usuarios strA = "SELECT TOP 1 * FROM TB_CONTROLFARMACOS WHERE FLD_MATCODIGO ='" & Me.txt_cod_interno & "' ORDER BY FECHA DESC " Set rsA = ABASTECIMIENTO.Execute(strA) 'MsgBox strA 'On Error Resume Next ' If rsA.EOF Then' rsA!ESTADO = Me.txt_estado' End If ' If rsA.EOF Then Exit Sub If (rsA!ESTADO <> i) Then STOCK1 = Val(rsA!STOCK) + Me.txt_cantidad Else STOCK1 = Val(rsA!STOCK) - Me.txt_cantidad End If 'Ingreso Datos saveSQL = "INSERT INTO TB_CONTROLFARMACOS(FLD_MATCODIGO, FECHA, " saveSQL = saveSQL & "CANTIDAD, STOCK, USUARIO, ESTADO) " saveSQL = saveSQL & "VALUES (" saveSQL = saveSQL & "'" & Me.txt_cod_interno & "', " saveSQL = saveSQL & "'" & Format(Me.dtp_fecha, "dd/mm/yyyy HH:mm") & "', " saveSQL = saveSQL & "'" & Me.txt_cantidad & "', " saveSQL = saveSQL & STOCK1 & ", " saveSQL = saveSQL & "'" & Principal.StatusBar1.Panels.Item(2) & "', " saveSQL = saveSQL & "'" & Me.txt_estado & "') " ABASTECIMIENTO.Execute (saveSQL) With Me.spr_ingreos .MaxRows = .MaxRows + 1 .Col = 1 .Row = .MaxRows .Text = Me.txt_cod_interno .Col = 2 .Row = .MaxRows .Text = Me.txt_nombre .Col = 3 .Row = .MaxRows .Text = Me.txt_cantidad End With limpiar Me.txt_cod_interno.SetFocus
End Function
Si pongo "On Error Resume Next", me pasa el error, hace todo, pero no me graba los datos a la tabla.
Ayuda please, he buscado por todos lados.
1 Respuesta
Respuesta de Roberto Alvarado
1