Solved

Exiting VB execution with an error.

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now