You are here:

Visual Basic/Call dll procedure from MS Access2003

Advertisement


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

Answer
Calling 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)

Visual Basic

All Answers


Answers by Expert:


Ask Experts

Volunteer


Robert Nunemaker

Expertise

String manipulation, Database access and usage, Class creation, and encapsulation are my strong suits. Active X Controls and DLL`s also. Although I don`t deal with Crystal - frankly because I don`t like it; I prefer to do things manually.

Experience

Employment history: Programmed with the Air Force for 15 years, and have continued in the private sector for the past 1 year. Used VB (all versions) for the past 8 years.

Organizations: MCP and MCSD certified.

Education: Computer Science Bachelor degree.

Awards: MCP and MCSD certified.

©2012 About.com, a part of The New York Times Company. All rights reserved.