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 "Consumible s", 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_Clic k()
On Error GoTo Error:
Dim Conexion As New ADODB.Connectio n
Dim Catalogo As New ADOX.Catalog
Dim ConjuntoRegistr os As New ADODB.Recordset
Conexion.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & Application.Cur rentProject.Pat h & "\Control de Herramientas.md b"
Set Catalogo.Active Connection = Conexion
ConjuntoRegistr os.Open "Consumible s", Catalogo.Active Connection, adOpenDynamic, adLockOptimisti c
ConjuntoRegistr os.Fields.Refre sh
ConjuntoRegistr os.AddNew
For Each Campo In ConjuntoRegistr os.Fields
If (Campo.Name = "Codigo") Then
valor = txtCodigo
Campo.Value = UCase$(valor)
ElseIf (Campo.Name = "Descripcio n") Then
valor = cmbDescripcion
Campo.Value = valor
ElseIf (Campo.Name = "CodigoProveedo r") Then
valor = txtProveedor
Campo.Value = Val(valor)
ElseIf (Campo.Name = "Localizaci on") Then
valor = txtLocalizacion
Campo.Value = valor
ElseIf (Campo.Name = "PuntoReord en") 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
ConjuntoRegistr os.Update
ConjuntoRegistr os.Close
Set ConjuntoRegistr os = Nothing
Set Catalogo = Nothing
Conexion.Close
Set Conexion = Nothing
MsgBox "Se dio de alta la herramienta con código " & txtCodigo, vbDefaultButton 1, "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
I have a form, so i can record data in a table called "Consumible s", 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_Clic k()
On Error GoTo Error:
Dim Conexion As New ADODB.Connectio n
Dim Catalogo As New ADOX.Catalog
Dim ConjuntoRegistr os As New ADODB.Recordset
Conexion.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & Application.Cur rentProject.Pat h & "\Control de Herramientas.md b"
Set Catalogo.Active Connection = Conexion
ConjuntoRegistr os.Open "Consumible s", Catalogo.Active Connection, adOpenDynamic, adLockOptimisti c
ConjuntoRegistr os.Fields.Refre sh
ConjuntoRegistr os.AddNew
For Each Campo In ConjuntoRegistr os.Fields
If (Campo.Name = "Codigo") Then
valor = txtCodigo
Campo.Value = UCase$(valor)
ElseIf (Campo.Name = "Descripcio n") Then
valor = cmbDescripcion
Campo.Value = valor
ElseIf (Campo.Name = "CodigoProveedo r") Then
valor = txtProveedor
Campo.Value = Val(valor)
ElseIf (Campo.Name = "Localizaci on") Then
valor = txtLocalizacion
Campo.Value = valor
ElseIf (Campo.Name = "PuntoReord en") 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
ConjuntoRegistr os.Update
ConjuntoRegistr os.Close
Set ConjuntoRegistr os = Nothing
Set Catalogo = Nothing
Conexion.Close
Set Conexion = Nothing
MsgBox "Se dio de alta la herramienta con código " & txtCodigo, vbDefaultButton 1, "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
Comment