Solved

64 bit vba timer module

Posted on 2016-10-09
2
69 Views
Last Modified: 2016-10-20
I am looking for a working 64  bit vba timer for ms access
thanks
0
Comment
Question by:Svgmassive
2 Comments
 
LVL 19

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points
ID: 41835884
'declare Sleep API
#If VBA7 Then             '  Code is running in the new VBA7 editor
  #If Win64 Then          '  Code is running in 64-bit version of Microsoft Office
    Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  #Else                   '  Code is running in 32-bit version of Microsoft Office
    Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  #End If
#Else                     ' Code is running in VBA version 6 or earlier
   Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If

Public Sub WaitMilliSeconds(nNumMilliseconds as long)
    'pause
    Sleep iNumMilliseconds
End Sub

Open in new window

wasn't sure if you meant Sleep (pause so much time) or if you meant to actually time something.  To time something, store the initial Timer() value since it gives you fractions of a second and then subtract that from the ending Timer() value
0
 
LVL 2

Expert Comment

by:Antonio Salva Ripoll
ID: 41837388
Hi Svgmassive.

You can use the Timer event of any form. This works regardless of the Access version.

You must specufy the time in miliseconds, and the form fires the event.

A small sample is this one:

'In a form called FormTimer
Private Sub Form_Timer()
    
    ' Your code goes here
    '
    '
    '
    
    'Fired
    MsgBox "Timer fired."
    
    Me.TimerInterval = 0
    
    DoCmd.Close acForm, Me.Name, acSaveNo
End Sub


'In a Standard module

Sub TimerTest()

    Dim mSeconds As Long
    
    mSeconds = 30000 'Assign a 30 seconds pause
    
    DoCmd.OpenForm "TimerForm", acNormal
    
    Forms!TimerForm.Visible = False
    
    'To start the timer
    Forms!TimerForm.TimerInterval = mSeconds
    
End Sub

Open in new window


This code is simple and works.

If you need to pause the code execution more time than a few seconds or minutes, you can also use a Do - Loop.

A sample could be:

Dim TimeStart As Date
    Dim TimeLap As Integer
    Dim TInter As String
    
    'Previous code

    'Pause code
    
    
    TimeStart = Now()
        
    TInter = "s" ' for seconds
    'TInter = "n" ' for minutes
    'TInter = "h" ' for hours
    'TInter = "d" ' for days
    
    Do
        DoEvents
        
    Loop Until DateDiff(TInter, Now, TimeStart) >= TimeLap

    'Code follows here

Open in new window


I hope this be helpful.

Best regards.

Antonio. (Barcelona, Spain)
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question