Advertisement

07.14.2008 at 03:51PM PDT, ID: 23564520
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

RAISEERROR not raising into VBA error routine

Asked by softdimensions in MS SQL Server, Microsoft Access Database, Microsoft ADP

Tags:

I have the following stored procedure and access vba script.

______________stored procedure_________________

ALTER PROCEDURE dbo.UpdateTask
      @task_id                  int,
      @task_type_id            int,
      @task_status_id            int,
      @order_item_id            int,
      @task_desc                  varchar(50),
      @order_datetime            datetime,
    @due_date                  smalldatetime,
      @instructions            varchar(1000),
      @user_id                  varchar(20),
      @ts                              rowversion
AS
BEGIN      
      declare @Error int;
      declare @RowCount int;      

      UPDATE task SET
            task_desc = @task_desc --, last_update_datetime = getdate()
      WHERE task_id = @task_id AND ts = @ts
      
      SELECT @Error = @@ERROR, @RowCount = @@ROWCOUNT;
      --return -1

      IF (@Error <> 0)
            RETURN -1

      IF (@RowCount = 0)
      BEGIN
            declare @lastUpdate datetime;
            declare @lastUpdateStr varchar(50);
            declare @lastUpdateUser varchar(20);

            SELECT @lastUpdate = last_update_datetime
            FROM task WHERE task_id = @task_id
            
            IF @lastUpdate is not null
            BEGIN
                  SET @lastUpdateStr = CONVERT(varchar(50),@lastUpdate,9); --date format?
                  RAISERROR('The row with id %d has been updated since it was read. Last update:%s by:. UPDATE fails.',16,1,@task_id,@lastUpdateStr);
                  --RETURN -1
            END
            ELSE
            BEGIN
                  RAISERROR('The row with id %d does not exist. UPDATE fails',16,1,@task_id);
                  --RETURN -1
            END
      END

      RETURN 0
END

_______________________Access Script____________________________


Public Function InsertTask(TaskTypeID As Integer, TaskStatusID As Integer, OrderItemID As Integer, taskDesc As String, OrderDate As Date, dueDate As Date, Instructions As String, user As String, Optional taskID As Long, Optional ts As Variant) As Boolean

On Error GoTo insertTaskErr

Set rs = New ADODB.Recordset
Set rs = New ADODB.Recordset
Dim cn As ADODB.Connection
Dim cmd As ADODB.Command

Dim prmTaskType As New ADODB.parameter
Dim prmTaskStatus As New ADODB.parameter
Dim prmOrderItemID As New ADODB.parameter
Dim prmTaskDescription As New ADODB.parameter
Dim prmTaskOrdered As New ADODB.parameter
Dim prmTaskDue As New ADODB.parameter
Dim prmTaskInstructions As New ADODB.parameter
Dim prmTaskUser As ADODB.parameter
Dim prmTaskTs As ADODB.parameter
Dim prmTaskID As ADODB.parameter
Dim myrowcount As Integer
           
            Set cmd = New ADODB.Command
            cmd.ActiveConnection = CurrentProject.Connection
            cmd.CommandType = ADODB.adCmdStoredProc
           
            If taskID > 0 Then
                cmd.CommandText = "UpdateTask"
            Else
                cmd.CommandText = "InsertTask"
            End If
           
            Set prmReturn = cmd.CreateParameter("Return_Value", adInteger, adParamReturnValue)
            cmd.Parameters.Append prmReturn
         
           
            If taskID > 0 Then
                Set prmTaskID = cmd.CreateParameter("@task_id", adInteger, adParamInput)
                cmd.Parameters.Append prmTaskID
                prmTaskID = taskID
            End If
           
            Set prmTaskType = cmd.CreateParameter("@task_type_id", adInteger, adParamInput)
            cmd.Parameters.Append prmTaskType
            prmTaskType = TaskTypeID
           
            Set prmTaskStatus = cmd.CreateParameter("@task_status_id", adInteger, adParamInput)
            cmd.Parameters.Append prmTaskStatus
            prmTaskStatus = TaskStatusID
           
            Set prmOrderItemID = cmd.CreateParameter("@order_item_id", adInteger, adParamInput)
            cmd.Parameters.Append prmOrderItemID
            prmOrderItemID = OrderItemID
           
            Set prmTaskDescription = cmd.CreateParameter("@task_desc", adVarChar, adParamInput, 50)
            cmd.Parameters.Append prmTaskDescription
            prmTaskDescription = taskDesc
           
            Set prmTaskOrdered = cmd.CreateParameter("@order_datetime", adDBTimeStamp, adParamInput)
            cmd.Parameters.Append prmTaskOrdered
            prmTaskOrdered = OrderDate
           
            Set prmTaskDue = cmd.CreateParameter("@due_date", adDBTimeStamp, adParamInput)
            cmd.Parameters.Append prmTaskDue
            prmTaskDue = dueDate
           
            Set prmTaskInstructions = cmd.CreateParameter("@instructions", adVarChar, adParamInput, 1000)
            cmd.Parameters.Append prmTaskInstructions
            prmTaskInstructions = Instructions
           
            Set prmTaskUser = cmd.CreateParameter("@user_id", adVarChar, adParamInput, 20)
            cmd.Parameters.Append prmTaskUser
            prmTaskUser = user
           
            If taskID > 0 Then
                Set prmTaskTs = cmd.CreateParameter("@ts", adVarBinary, adParamInput, 8)
                cmd.Parameters.Append prmTaskTs
                prmTaskTs = ts
            End If
           
           
                       
           
             cmd.Execute
           
       
           
            InsertTask = True

insertTaskExit:
Exit Function

insertTaskErr:
MsgBox Err.Number & " " & Err.Description
InsertTask = False
Resume insertTaskExit

End Function

_________________________End of Access Script____________________

The problem is that I can't get the RAISEERROR to send the vba code into the Error Loop of VBA.  The only time this worked is if I included a RAISEERROR at the top of the stored procedure.

Any thoughts would be appreciated.Start Free Trial
[+][-]07.14.2008 at 04:03PM PDT, ID: 22002874

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 04:15PM PDT, ID: 22002933

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 06:52PM PDT, ID: 22003629

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.08.2008 at 08:47AM PDT, ID: 22191009

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, Microsoft Access Database, Microsoft ADP
Tags: SQL Server 2000/Microsoft Access 2003
Sign Up Now!
Solution Provided By: softdimensions
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080924-EE-VQP-39 / EE_QW_2_20070628