Solved

64 bit vba timer module

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can not open the Access Help ? 3 53
Delete Records on a Form in Microsoft Access 5 39
Access sql to sql server express 10 32
Question about DB Schema 27 52
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
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 views 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 Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

786 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