Solved

Exiting VB execution with an error.

Posted on 2004-09-24
4
331 Views
Last Modified: 2010-05-02
 Hello everybody,

  We've got an SQL-Server's job executing an VB 6.0 exe. We want to know whether this execution
failed or not. We've tried using Err.Raise or Stop but execution never ends (executing from this
SQL-Server 2000 job). Could anybody help?

  Thanks in advance,

  Jon
0
Comment
Question by:JonGartzia
4 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12141875
Have you set the time out value

ie

set cn = Server.CreateObject("ADODB.Connection")
cn.CommandTimeout = 60
cn.open sConnString
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 12142483
So you want an exit code to be generated from your VB6 app that can be trapped by your SQL server job?  (Typically 0 means success and anything indicates something went wrong.)  Here is how you can do it.  Just set the global exitCode variable to the value you want and then use Unload Me to end the program.

' API Call to generate an Exit Code *** Do all clean up First! ***
' When this function is called the program IMMEDIATELY exits with the
' specified exit code.
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)

' Used to determine if we are running in the IDE or not
Private Declare Function GetModuleFileName Lib "kernel32" Alias _
    "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, _
    ByVal nSize As Long) As Long

Private exitCode as Long ' Set this global variable to the code you want to exit with

Private Sub Form_Unload(Cancel As Integer)
    Dim strFileName     As String
    Dim lngCount        As Long
           
    ' Produce an exit code that is trappable by other programs
    strFileName = String(255, 0)
    lngCount = GetModuleFileName(App.hInstance, strFileName, 255)
    strFileName = Left(strFileName, lngCount)
    If UCase(Right(strFileName, Len(App.EXEName) + 4)) = UCase(App.EXEName) & ".EXE" Then
        ExitProcess exitCode ' We are not in the IDE...actually exit with code
    Else
        MsgBox "Exit Code: " & exitCode ' We are in the IDE...simulate exit w/ code
    End If
End Sub
0
 
LVL 1

Author Comment

by:JonGartzia
ID: 12142704
Thank you very much, Idle Mind. It works.
0
 

Expert Comment

by:mikey2nicey
ID: 12274814
I was looking for something very similar and this was just the job Idle Mind. Thanks.

Mike
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to open Waze.com/livemap from address saved in DB? 26 173
Restricting text box entry from \/:?<>"| 9 76
Can we place a tooltip on the actual vb6 form 5 35
Help me. 3 43
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now