Visual Basic/Call dll procedure from MS Access2003
Expert: Robert Nunemaker - 9/10/2006
Question
-------------------------
Followup To
Question -
Hi Robert,
i am working on a project that need to call dll and display data every 2second. i would appreciate if you can guide me or give a sample code.
thanks in advance.
regards,
kvu
Answer -
Your question is far too generic. However, some code similar to this will work for you. The code itself isn't really very important. Just the part where you want to do something. It MUST be placed in a module. Calling StartTimer is what actually starts the polling process and the interval is how long in milliseconds, so you'd want 2000. Call StopTimer when you don't want it to poll anymore.
Private Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Private mlngTimerID As Long
Public Sub StartTimer(lngInterval As Long)
mlngTimerID = SetTimer(0, 0, lngInterval, _
AddressOf TimerCallBack)
End Sub
Public Sub TimerCallBack(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long)
'Do Something Here
End Sub
Public Sub StopTimer()
KillTimer 0, mlngTimerID
End Sub
---------------
Hi Robert,
Thanks for qick prompt of reply. Actually, I am trying to call a dll that was created from VC+
I am not sure exactly how to do this. I've seen examples of subclassing, but they all seemed to pertain to window application or forms not to a dll.
Any help would be greatly appreciated!
Many thanks,
kvu
AnswerCalling the DLL is no different in Access as in any other VB app. Just use Tools/References to find your DLL, and then after you create your reference, create your Declare statement the module desired. Then call it. You aren't really subclassing. You are simply instantiating an object created elsewhere.
So if you wanted to run a function from the DLL every 2 seconds, you might add to the above code:
Private Declare Sub myMethod (myArguments...)
and where you see "Do Something Here", execute it with:
Call myMethod(myArguments)