Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7779661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:41:46+00:00 2026-06-01T18:41:46+00:00

Currently I am trying to implement a timer class in VBA. For that purpose

  • 0

Currently I am trying to implement a timer class in VBA. For that purpose I use the SetTimer and KillTimer functions of the Windows API…

This is the interface from Msdn:

  UINT_PTR WINAPI SetTimer(
  __in_opt  HWND hWnd,
  __in      UINT_PTR nIDEvent,
  __in      UINT uElapse,
  __in_opt  TIMERPROC lpTimerFunc
);

And this is the way I declared the function wihtin my VBA-Module:

Private Declare Function SetTimer Lib "user32" (ByVal Handle As Long, _
                                                ByVal TimerIDHandle As Any, _
                                                ByVal ElapseTime As Long, _
                                                ByVal AddressOfAndYourHandlerFunctionName As Long) As Long

                                                'TimerIDHandle is of Type Any so I can pass Nothing to the function

I then Call the function this way:

Dim TimerID As Long

TimerID = SetTimer(Application.hWndAccessApp, ByVal 0&, Timer.Timeout, AddressOf TimeOutHandler)

As Vba does not accept a “Null” I have tried implementing “ByVal 0&”. Is this the right way to do it?
Anyway…I call this function several times from the same Application and the function always returns 1 as an Identifier even though, according to Msdn, the function should return a unique ID for each timer that is created in the Window handle of the current Access Application.

Furthermore when I created only one timer the Callback function gets Called, but the Timer ID is given as 0, whereas the Settimer-Function returned a 1 at the time of initialization.
Here is my Callback Function Header:

Private Sub TimeOutHandler(ByVal WindowHandle As Long, _
                           ByVal TimerMessage As Long, _ 
                           ByVal TimerID As Long, _ 
                           ByVal ElapsedTime As Long)

Where am I wrong?

Any help is greatly appreciated of course 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:41:47+00:00Added an answer on June 1, 2026 at 6:41 pm

    It worked. If it failed then it would have returned 0. You get a 0 for TimerID in the callback because you passed a 0 for the nIDEvent argument when you created the timer. You’ll need to use the value that SetTimer returned to call KillTimer(). Think of it as a timer ‘handle’.

    You’ll never get this code working in 64-bit mode so just declare the 2nd argument as Long.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to implement a socket server that enables the clients to send
I'm currently trying to implement a Table View on my iPhone app that grabs
I am trying to use the MailMessage class to construct e-mail messages that are
I am currently trying implement a QThread that contains a socket connection. The socket
I am trying to implement a class, that subclasses NSObject directly, that can only
I'm currently trying to implement a simple Add-In for InfoPath 2010 Filler/Editor mode, which
I am currently trying to implement a marker interface in c#. But I haven't
I'm trying to implement a mailing list system for my application. I'm currently using
I'm trying to implement a little function in my app. I am currently playing
I'm currently working on a ASP.Net 3.5 project and trying to implement session timeout

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.