Handling Errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oc20
    New Member
    • Dec 2006
    • 9

    Handling Errors

    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
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Can you tell us exactly which lines are causing the errors. If you click on Debug when the error appears it should go to the code and highlight the line in yellow.

    Mary

    Comment

    • oc20
      New Member
      • Dec 2006
      • 9

      #3
      The thing is that the error only appears when it wants to . . . i know this sound strange but thats what is happening.

      Comment

      • MMcCarthy
        Recognized Expert MVP
        • Aug 2006
        • 14387

        #4
        Originally posted by oc20
        The thing is that the error only appears when it wants to . . . i know this sound strange but thats what is happening.
        Unfortunately unless we know where the error is appearing and under what circumstances theres not much we can do. Unless someone gets inspired?

        You could try changing your code to DAO as it works better (in my opinion) with the Jet Engine and is easier to code.

        Mary

        Comment

        • oc20
          New Member
          • Dec 2006
          • 9

          #5
          Well, thanks for your help Mary.

          This site its great!

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #6
            Originally posted by oc20
            Well, thanks for your help Mary.

            This site its great!
            You're welcome

            Merry Christmas

            Mary

            Comment

            Working...