Solved

Exiting VB execution with an error.

Posted on 2004-09-24
4
332 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

813 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

16 Experts available now in Live!

Get 1:1 Help Now