Results 1 to 9 of 9
  1. #1
    Join Date
    May 2002
    Posts
    395

    Unanswered: Re: Error handling/trapping

    Hi everyone,

    I am trying trap these two errors when a function is called I tried On Error GoTo ErrorHandler and On Error Re.sume Next. The errors are still popping up.

    Here is my code:
    Function load_rst()
    On Error Resume Next
    Dim str As String
    If Forms!start_inspection!multiple_type = 1 Then
    str = "Select tblTmp_inspec.id, tblTmp_inspec.bag_num, tblTmp_inspec.quantity, tblInspection_types.inspection_type_id, tblInspection_types.type_desc, tblTmp_inspec.partial, tblTmp_inspec.complete From tblTmp_inspec "
    str = str & "Inner join tblInspection_types On tblTmp_inspec.inspection_type = tblInspection_types.inspection_type_id "
    str = str & "Where tblTmp_inspec.partial > 0 Or tblTmp_inspec.complete > 0;"
    'Me.RecordSource = str

    If (Err.Number = "30014") Or (Err.Number = "30013") Then
    GoTo err_exit
    Else
    -->Error occurred here Me.RecordSource = str
    Me.UniqueTable = "tblTmp_inspec"
    End If
    Else
    str = "Select tblTmp_inspec.id, tblTmp_inspec.bag_num, tblTmp_inspec.quantity, tblInspection_types.inspection_type_id, tblInspection_types.type_desc, tblTmp_inspec.partial, tblTmp_inspec.complete From tblTmp_inspec Inner Join tblInspection_types "
    str = str & "ON dbo.tblTmp_inspec.inspection_type = dbo.tblInspection_types.inspection_type_id "
    str = str & "Order by bag_num"
    Me.RecordSource = str
    End If

    err_exit:
    Exit Function

    End Function

    Is there any way I can write this or how I can fix this?

    Thanks much!

  2. #2
    Join Date
    Sep 2004
    Posts
    161
    Try this
    If (Err.Number = 30014) Or (Err.Number = 30013) Then

  3. #3
    Join Date
    May 2002
    Posts
    395

    Re: Please help with error handling/trapping

    Thanks for your reply.
    I tried it but it still not working.
    I really need to get the Error handling working. I know what errors will pop up and where but I can't trap them. Please help!

  4. #4
    Join Date
    Sep 2004
    Posts
    161
    i suggest you use this syntax
    Code:
    Function load_rst()
    On Error Goto ErrorHandler
    Dim str As String
    If Forms!start_inspection!multiple_type = 1 Then
    ......
    
    
    Else
    ....
    End If
    Me.RecordSource = str
    ...........
    ErrorHandler:
    If Err.Number = 30014 Or Err.Number = 30013 Then
    GoTo err_exit
    Else
    Me.UniqueTable = "tblTmp_inspec"
    resume next
    End If
    
    err_exit:
    Exit Function
    
    End Function

  5. #5
    Join Date
    May 2002
    Posts
    395

    Angry Re: Please HELP! with error handling/trapping

    Thanks for your reply.

    I modified the code as you suggested. I moved the recordsource to the end of the IF statement and and still error occurs on the recordsource line and Error (30014) message appeared then execute the errorHandler.
    How can I get the error message from appearing??
    I would appreciate any suggestions.
    Thank you!

  6. #6
    Join Date
    Sep 2004
    Posts
    161
    Please
    Can you describe your error and your environnement (DAO, ADO,...)

  7. #7
    Join Date
    May 2002
    Posts
    395

    Re: Please HELP with Error Handling/Trapping

    Thanks again for replying.

    I'm using Access 2000 FE & SQL Server 2000 BE and ADO thru VBA.
    I have a subform that gets its recordsource from a temp table and inspection_type tbl. The temp table is created when the subform opens and gets deleted in closing of subform.
    The temp table has five fields: bag_num, quantity, inspection_type, partial, complete. The inspection_type tbl: id, desc_type.
    I joined the two tables and get bag_num, quantity,desc_type. The partial and complete are check boxes the user is able to select these check boxes.
    The subform displays all bags of work order number.

    when clicking on OK
    This subform display only the records that the user checked.
    This is all fine and good at this point.
    *******
    But when uncheck/check a check box the check mark is uncked/cked then when I clicked on another I get
    Run-time error 30014:

    The data was added to the database but the data won’t be displayed in the form because it doesn’t satisfy the criteria in the underlying record source.
    or
    Run-time error 30013:

    You can’t update the record because another user or application deleted it or changed the value of its primary key.

    *****

    this is the subform's recordsource code:
    str = "Select tblTmp_inspec.id, tblTmp_inspec.bag_num, tblTmp_inspec.quantity, tblInspection_types.inspection_type_id, tblInspection_types.type_desc, tblTmp_inspec.partial, tblTmp_inspec.complete From tblTmp_inspec "
    str = str & "Inner join tblInspection_types On tblTmp_inspec.inspection_type = tblInspection_types.inspection_type_id "
    str = str & "Where tblTmp_inspec.partial > 0 Or tblTmp_inspec.complete > 0" Me.RecordSource = str
    Me.UniqueTable = "tblTmp_inspec"


    This is really fustrating!!! If only error handling will work or any other way to do this I am most willing to try.
    Thank you for responding.

  8. #8
    Join Date
    Sep 2004
    Posts
    161
    How connect you to your SQL server ?

  9. #9
    Join Date
    May 2002
    Posts
    395

    Angry RE: HELP in Error Handling

    HI,

    I use currenproject property to connect SQL Server.
    ie:
    str = "Create Table tblTmp_inspec(id integer identity Primary Key, bag_num integer.."
    CurrentProject.Connection.Execute str
    Do you have an idea what seems to be the problem?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •