Solved

64 bit vba timer module

Posted on 2016-10-09
2
37 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 18

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points
Comment Utility
'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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now