How Do I Call a vb6 App

G

Guest

I am working on a vb6 exe or dll and would like to know how to call it from a
command button on an Access 2003 form.
The app will run its own vb 6 form with image boxes and update records in
the access database table.
When closed, it will return control to the Access form that called it.
Thanks in advance.
 
T

Tony Toews [MVP]

JO said:
I am working on a vb6 exe or dll and would like to know how to call it from a
command button on an Access 2003 form.

If exe then shell.

If dll then you need to put the call to the dll in the code similar to
the following code

Private Declare Sub sapiCopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(ByVal cbCopy As Long)

However I've never called a VB DLL from within Access so there could
be lots of errors in the above. Call it air code.

Ton
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
G

Guest

Hi Tony,
However I've never called a VB DLL from within Access so there could
be lots of errors in the above. Call it air code.

I have called a VB DLL from within Access. It is done by setting an object
variable, very similar to how one would automate Excel, Outlook, etc. ie:

Dim oAero As Object
Set oAero = CreateObject("AeroTools.Interpolate.1")

This DLL file is used to perform linear interpolation of engine data. In the
example shown below, I've implemented it by using late binding. This .DLL
file is only available to folks within the company that I work at, so I
cannot distribute it to anyone who might ask. Sorry. Anyway, here is the
module that shows the complete useage of this .DLL file (complete with my
Debug.Print statements as well!):


'The description of the AeroTools Programming Interface can be found here:
'http://confluence-pilot.wiki.boeing.com/confluence/download/attachments/11923/AeroTools_COM_Help.xml

Option Compare Database
Option Explicit

'Declared as dynamic (resizable) public array, which is zero based.
Public gTempVolt() As Single
Dim oAero As Object

Public Function DetermineVoltage(varTemp As Variant) As Variant
On Error GoTo ProcError

'Input: Temperature (celcius)
'Output: Interpolated millivolt value

Dim a As Variant ' dummy variable
Dim i As Integer, xval As Single, yval As Single
Static fObjectHasBeenSet As Boolean

If Not IsNull(varTemp) Then
If (Not (fObjectHasBeenSet)) Then
Set oAero = CreateObject("AeroTools.Interpolate.1")
Debug.Print "Hello"
For i = 0 To UBound(gTempVolt)
xval = gTempVolt(i, 0)
yval = gTempVolt(i, 1)
a = oAero.AddXY(xval, yval)
Next i

fObjectHasBeenSet = True
End If

DetermineVoltage = Format(oAero.Linear(varTemp), "0.00")

Else
DetermineVoltage = Null
End If

ExitProc:
'Cleanup
On Error Resume Next
'Set oAero = Nothing
Exit Function
ProcError:
Debug.Print "DetermineVoltage Function:"
Debug.Print "Error " & Err.Number & ": " & Err.Description
Debug.Print
Select Case Err.Number
Case 9 'Subscript out of range --->Reinitialize global arrays
EnumerateOutputVoltageTable
Resume
Case 429, -2147024770 '429 = ActiveX component can't create object /
-2147024770 = Automation error - The specified module could not be found.
MsgBox "Cannot find the dynamic link library file:
'AeroTools.dll' or it is not properly registered." & vbCrLf _
& "You must install and register this file correctly.",
vbCritical, "Automation Error..."
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in EnumerateTables function..."
End Select
DetermineVoltage = Null
Resume ExitProc
End Function

Function EnumerateOutputVoltageTable() As Boolean
On Error GoTo ProcError
'Purpose: Populate the global arrays with the SHP values from TableA and
TableB

'Debug.Print "Enumerating Output Voltage Table"

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim intRecordCount As Integer
Dim i As Integer, j As Integer

Set db = CurrentDb()

strSQL = "SELECT CelciusTemperature, MillivoltsResponse " _
& "FROM ThermocoupleOutputVoltages " _
& "ORDER BY CelciusTemperature"

Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)

'Move to last record, then return, so that we can get accurate recordcounts
rs.MoveLast: rs.MoveFirst
intRecordCount = rs.RecordCount

'Resize our zero-based array gTempVolt and populate with data.
ReDim gTempVolt(intRecordCount - 1, 1)

For i = 0 To intRecordCount - 1
For j = 0 To 1
gTempVolt(i, j) = rs(j)
Next j
rs.MoveNext
Next i

EnumerateOutputVoltageTable = True

ExitProc:
'Cleanup
If Not rs Is Nothing Then
rs.Close: Set rs = Nothing
End If
Set db = Nothing
Exit Function
ProcError:
Debug.Print "EnumerateOutputVoltageTable Function:"
Debug.Print "Error " & Err.Number & ": " & Err.Description
Debug.Print
MsgBox "Error " & Err.Number & ": " & Err.Description, , _
"Error in EnumerateTables function..."
EnumerateOutputVoltageTable = False
Resume ExitProc
End Function

'**************End Code**************************


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
N

Norman Yuan

With VB6, you can either make an AtiveX exe application, or ActiveX DLL
project.

With ActveX EXE, it is a stand-alone app and also activeX automate-able, so
you can automate it from your Access application. However, it is out-process
to the Access app. the communication between your Access app and the exe is
a bit slow.

With ActiveX DLL, the code in the dll file rub inside your Access app, just
as part of your Access app. You set reference to the DLL in your Access
application (unless you do late binding). From your brief description, it
seems ActiveX DLL would be easy choice.

Since you want to display a image box, you can even consider to make an
ActiveX Control project in VB6. So the image box with code to manipulate
data would be easily re-used in mitiple forms and applications
 
G

Guest

Thanks Tony!

Tony Toews said:
If exe then shell.

If dll then you need to put the call to the dll in the code similar to
the following code

Private Declare Sub sapiCopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(ByVal cbCopy As Long)

However I've never called a VB DLL from within Access so there could
be lots of errors in the above. Call it air code.

Ton
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
G

Guest

Thank you very much, Tom, for taking the time to answer this. I originally
developed my complete app in VB3, so bringing the image box editing code
forward to VB6 should be very easy.
The Access 2003 app is finished, so this will polish things off.
 
G

Guest

Thank you, Norman. Your reply is so concise and well-done! This will be of
great help as I finish off my Access 2003 app! I really appreciate you
taking the time to reply.
I actually developed my entire app years ago in Vb3, it is still in heavy
use today, and the image box editing form has been fast all these years.
Everything is nicely finished in Access 2003 except this part of it and,
although I have done lots of work in Access 97, 2002, and 2003, I have not
yet needed to do this.
I assume VB6 is stand-alone for purchase outside Visual Studio and probably
is the best vehicle for the outside call?
 
G

Guest

Thank you all for taking the time to reply. I am sure others will benefit
from your responses, too! The responses are very helpful!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top