Solved

64 bit vba timer module

Posted on 2016-10-09
2
115 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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