Hi, im working with Access 2002 and im having some troubles with errors.
I have a form, so i can record data in a table called "Consumibles", but i wanted my own form to do this task, so i made a form with 6 text box, 1 combo box and one button.
The thing is that i dont know why some errors appears, the numbers of these errors are -2147467259 and 0. Could you please help me? What is causing this error and what can i do to solve this situation?
The code of the button in the Click event is:
Private Sub cmdAceptar_Click()
On Error GoTo Error:
Dim Conexion As New ADODB.Connection
Dim Catalogo As New ADOX.Catalog
Dim ConjuntoRegistros As New ADODB.Recordset
Conexion.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.CurrentProject.Path & "\Control de Herramientas.mdb"
Set Catalogo.ActiveConnection = Conexion
ConjuntoRegistros.Open "Consumibles", Catalogo.ActiveConnection, adOpenDynamic, adLockOptimistic
ConjuntoRegistros.Fields.Refresh
ConjuntoRegistros.AddNew
For Each Campo In ConjuntoRegistros.Fields
If (Campo.Name = "Codigo") Then
valor = txtCodigo
Campo.Value = UCase$(valor)
ElseIf (Campo.Name = "Descripcion") Then
valor = cmbDescripcion
Campo.Value = valor
ElseIf (Campo.Name = "CodigoProveedor") Then
valor = txtProveedor
Campo.Value = Val(valor)
ElseIf (Campo.Name = "Localizacion") Then
valor = txtLocalizacion
Campo.Value = valor
ElseIf (Campo.Name = "PuntoReorden") Then
valor = txtPuntoReorden
Campo.Value = valor
ElseIf (Campo.Name = "Precio") Then
valor = txtPrecio
Campo.Value = Val(valor)
ElseIf (Campo.Name = "Cantidad") Then
valor = txtCantidad
Campo.Value = Val(valor)
ElseIf (Campo.Name = "Total") Then
valor = Val(txtCantidad) * Val(txtPrecio)
Campo.Value = Val(valor)
End If
Next
ConjuntoRegistros.Update
ConjuntoRegistros.Close
Set ConjuntoRegistros = Nothing
Set Catalogo = Nothing
Conexion.Close
Set Conexion = Nothing
MsgBox "Se dio de alta la herramienta con código " & txtCodigo, vbDefaultButton1, "OK"
txtCodigo = ""
txtProveedor = ""
txtCantidad = ""
txtPrecio = ""
txtLocalizacion = ""
txtPuntoReorden = ""
Error:
If Err.Number = 94 Then
MsgBox "Make sure all data has been provided", vbCritical, "Error"
ElseIf Err.Number = -2147217887 Then
MsgBox "The code of the tool has already been registered", vbCritical, "Error"
ElseIf Err.Number = -2147352571 Then
MsgBox "Enter invalid data in numerical fields", vbCritical, "Error"
Else
MsgBox "Error" & Err.Number
End If
End Sub