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
__________________________________________