Results 1 to 9 of 9

Thread: Error Traping

  1. #1
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665

    Unanswered: Error Traping

    Having some problems with error trapping, this is my first crak at it so im a bit new to it. This is the bit of code thats important

    On Error GoTo NOCUSTOMERSELECTED

    ' delete qrydef if it exists
    For Each qdf In Cur_DB.QueryDefs
    If qdf.Name = "Multi_Graph" Then
    Cur_DB.QueryDefs.Delete "Multi_Graph"
    Exit For
    End If
    Next qdf
    DoCmd.SetWarnings True

    Set Multi_Graph_RS = Cur_DB.CreateQueryDef("Multi_Graph", "select account , Week as [time] " & Measuerment & " as [Metric] " & _
    " From DM_GLOBAL_ACCOUNTS_AGGR_TBL" & _
    " Where account is not null" & _
    " and week between " & From_week & to_week & _
    " and account in (" & Right(strItems, Len(strItems) - 2) & ")" & _
    Direction & String_Var & _
    " Group by account, Week " & _
    " Order by Week asc, Account asc")
    Multi_Graph_RS.Connect = "ODBC;Description=DataWarehouse;DRIVER=SQL Server;SERVER=scnc044db;UID=globalsales;PWD=global ;Network=DBMSSOCN;"

    Multi_Graph_Chart.RowSourceType = "table/query"
    Multi_Graph_Chart.RowSource = "TRANSFORM Sum(Multi_Graph.Metric) AS [Metric] SELECT mid(Multi_Graph.[Time],1,4)& '_' & mid(Multi_Graph.[Time],5,2) AS [Time] FROM Multi_Graph GROUP BY mid(Multi_Graph.[Time],1,4)& '_' & mid(Multi_Graph.[Time],5,2) PIVOT Multi_Graph.account;"


    Multi_Graph_Chart.Refresh
    Multi_Graph_Chart.Visible = True
    Graph_Title = graph_title_text
    Graph_Title.Visible = True
    Criteria_Label.Visible = True

    Criteria_Text.Value = From_week_Value & to_week_Value & Account_Value & String_Value & Direction_Value

    NOCUSTOMERSELECTED:
    Dim no_customer As String
    If Err.Number = 5 Then
    no_customer = MsgBox("Please Select An Account", vbOKOnly, "Unknown Account")
    End
    Else: MsgBox Err.Description
    End If

    End Sub

    If i leave it like this it will produce a msg box with nothing in it indicating taht it went to this step even though there were no errors.

    Why did it do that?
    Jim

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    and if you use
    msgbox "This is the trapped err.number: " & err.number
    do you get your anticipated 5 ?

    also slightly confused by your attempt to return the TRUE/FALSE result of a msgbox()=normallyAvbConstant to a string.

    the usage i am familar with is:
    IF MsgBox("xx")=vbYes THEN
    ELSE
    ENDIF
    '...or some other appropriate vbConst in place of vbYes

    izy

  3. #3
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665
    Originally posted by izyrider
    and if you use
    msgbox "This is the trapped err.number: " & err.number
    do you get your anticipated 5 ?

    also slightly confused by your attempt to return the TRUE/FALSE result of a msgbox()=normallyAvbConstant to a string.

    the usage i am familar with is:
    IF MsgBox("xx")=vbYes THEN
    ELSE
    ENDIF
    '...or some other appropriate vbConst in place of vbYes

    izy
    i do know that the error that I am looking for is 5 and when i get that error i want to display the msg box and then end the process

    Im not sure what you mean by returning a true/false for a msg box, im only using the msg box to tell the enduer his/her mistake it has no baring on what happens next.
    when this code is run and there is no error i still get the msb box from this line
    Else: MsgBox Err.Description

    I shouldnt get it ther is no error it should not go to the error handeling at all.
    thats what I dont understand
    Jim

  4. #4
    Join Date
    Nov 2002
    Location
    Hamilton,Ontario
    Posts
    132

    Re: Error Traping

    Jim [/SIZE][/QUOTE]

    The mistake is so obvoius...
    Either if you have error or not it will go to error handler unless u do this

    'Place Exit Sub before error handler
    'now the only time it will go to error handler is when u will get error

    Exit Sub

    NOCUSTOMERSELECTED:
    Dim no_customer As String
    If Err.Number = 5 Then
    no_customer = MsgBox("Please Select An Account", vbOKOnly, "Unknown Account")
    End
    Else: MsgBox Err.Description
    End If
    'Place exit sub at the end
    Exit Sub
    End Sub

  5. #5
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665

    Re: Error Traping

    Originally posted by VBAPROGRAMMER
    Jim
    The mistake is so obvoius...
    Either if you have error or not it will go to error handler unless u do this

    'Place Exit Sub before error handler
    'now the only time it will go to error handler is when u will get error

    Exit Sub

    NOCUSTOMERSELECTED:
    Dim no_customer As String
    If Err.Number = 5 Then
    no_customer = MsgBox("Please Select An Account", vbOKOnly, "Unknown Account")
    End
    Else: MsgBox Err.Description
    End If
    'Place exit sub at the end
    Exit Sub
    End Sub [/SIZE][/QUOTE]

    damn it i knew there was a trick to that i thought it had to be before the exit sub not after...... stupid me
    thanx man
    Jim

  6. #6
    Join Date
    Nov 2002
    Location
    Hamilton,Ontario
    Posts
    132

    Re: Error Traping

    Im glad it helped . kewl

  7. #7
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665

    Re: Error Traping

    Originally posted by VBAPROGRAMMER
    Im glad it helped . kewl
    Worked like a champ, thanx again
    Jim

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    sorry, interrupted so i couldn't complete the previous effort. trying again:

    msgbox() returns a number ...honestly i forget which, but it's either byte or integer. it take the form:

    intReturn = msgbox("dialogText", vbConstA + vbConstB, "dialogTitle"

    or is it bytReturn ...?

    you should get all the usable vbConstX when you try typing the code else try help... you can add any number of vbConsts ...thus defining the buttons and the lets-call-it-an-icon. use it in the form:

    if msgbox("Do you want to?", vbQuery + vbYesNo, "Well?") = vbYes then
    'the user wants to
    else
    'the user does not want to
    endif




    if you don't want a return, you don't want the msgbox function, so drop the ():
    msgbox "hello", vbOKonly, "Hello Box"
    ...this returns nothing.

    BOTH msgbox AND msgbox() will display the "prompt", buttons, "title". The function returns a value, the method just displays.




    private function myFunc() as boolean
    on error goto err_myFunc
    'some code which might produce errors
    'more poss error producing code
    'end of error prone code
    myFunc = TRUE 'prepare a happy landing
    exit_err_myFunc:
    'any tidy-up code you might need
    exit function
    err_myFunc:
    myFunc = FALSE 'prepare the unhappy exit
    msgbox "You screwed up", vbOKonly, "Operator error"
    'and other error handling code you want
    resume exit_err_myFunc
    end function


    you could equally concatenate err.number, .description etc into your: msgbox "I found error " & err.number, vbOKonly, "Fatal Error"

    or take specific action depending on the err.number
    if err.number = 5 then
    else
    endif


    izy

  9. #9
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    sorry vbaprogrammer... got stuck on the phone and you got there first.

    izy


    ...but (last edit and i shut up!) i'm still not happy returning the result of msgbox() to a STRING. either use the method or return to an INTEGER

    izy
    Last edited by izyrider; 01-14-03 at 15:56.

Posting Permissions

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