Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2010
    Posts
    186

    Unanswered: Access 2007 timer interval - lowest/fastest setting

    I'm collecting some data on Form 1, and a minimized Form 2 populates with this information on Form_Current then closes Form 2 and Form 1 on timer interval 1000. I need to speed it up a bit.

    Form 2 is opening to a new record after update of the last field in Form 1....seems instantaneous (word?), but are there certain intervals that have to be allowed to carry out the event in Form_current?

    This can literally be behind the scenes - very quick...as long as Form 2 gets it's data

    Thanks alot!!

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by Foskbou View Post
    ...I need to speed it up a bit...

    ...there certain intervals that have to be allowed to carry out the event in Form_current?
    I have read this post half a dozen times in the past 34 hours and I still have no idea as to what you're trying to convey! And I'm guessing, since it's been viewed almost two dozens times and no one has posted a response, that others are having the same problem with it.

    It might help if you tried to explain what is meant by

    "...there certain intervals that have to be allowed to carry out the event in Form_current"

    for starters.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Mar 2009
    Posts
    5,441
    Provided Answers: 14
    Quote Originally Posted by Missinglinq View Post
    I have read this post half a dozen times in the past 34 hours and I still have no idea as to what you're trying to convey!
    Ditto for me.

    Generally speaking it's never a good idea to rely on a Timer to (try to) control interactions between Forms.

    Access is an Events driven system and you cannot simply assert that something on a Form (e.g. the completion of a function, VBA or internal) will be in a certain state after a certain amount of time.

    If you need such a control in your application you can use specific events you create with the RaiseEvent statement. A very simple way of achieving this consists in creating a Class that will be shared among several objects (Forms, Reports, other classes, etc.) and that will act as a shuttle to relay signals among these objects.

    Here's an example of this method. It does not perform anything useful but helps to understand how the technique works. In reality this class has many other properties and methods that are not present here.
    Code:
    Option Compare Database
    Option Explicit
    '
    ' ***************************
    ' *** Class Cls_DataArray ***
    ' ***************************
    '
    ' This class is used to carry data among several objects.
    '
    ' Each object using it has a pointer on the same instance of the class.
    '
    Private Type DataArray
        Value As Variant
        Name As String
        Type As Long
    End Type
    
    Public Event DataLoaded()
    
    Private m_varArray() As DataArray
    Private m_lngMaxIndex As Long
    Private m_booAllowNull As Boolean
    Private m_booDirty As Boolean
    
    Public Function Load(rst As DAO.Recordset) As Long
    
        Dim i As Integer
        
        With rst
            m_lngMaxIndex = .Fields.Count - 1
            ReDim m_varArray(-1 To m_lngMaxIndex)
            If (.BOF And .EOF) = False Then
                .MoveFirst
                For i = 0 To m_lngMaxIndex
                    m_varArray(i).Value = .Fields(i).Value
                    m_varArray(i).Name = .Fields(i).Name
                    m_varArray(i).Type = .Fields(i).Type
                Next i
            Else
                For i = 0 To m_lngMaxIndex
                    m_varArray(i).Value = Null
                    m_varArray(i).Name = .Fields(i).Name
                    m_varArray(i).Value = .Fields(i).Type
                Next i
            End If
        End With
        m_booDirty = False
        Load = i
        RaiseEvent DataLoaded
    
    End Function
    Ex: Form1 creates the instance of the class using:

    Code:
           Private m_clsDataArray As Cls_DataArray
           Set m_clsDataArray = New Cls_DataArray
    When it opens Form2, it calls its Initialize Method and passes a pointer to the instance of the class:
    Code:
           Private m_Form2 As Form
           DoCmd.OpenForm "Form2"
           Set m_Form2 = Forms("Form2")
           m_Form2.Initialize m_clsDataArray
    In the declaration section of Form2 we have:
    Code:
        Private m_clsDataArray As Cls_DataArray
    and there is the Initialize function:
    Code:
        Set m_clsDataArray = DataArray
        m_clsDataArray.Load Me.RecordsetClone
    In Form3 the class Cls_DataArray is declared like this:
    Code:
    Private WithEvents m_clsDataArray As Cls_DataArray
    Form3 also receives a pointer on m_clsDataArray when it's open, also using an Initialize function:
    Code:
    Public Function Initialize(ByVal DataArray As Cls_DataArray)
    
        Set m_clsDataArray = DataArray
        
    End Function
    Form3 fetches the data from the instance of the class m_clsDataArray and uses it in a way that's irrelevant for the example.

    When the event DataLoaded is raised by the instance of the class Cls_DataArray, the signal is received by Form3, like this:
    Code:
    Private Sub m_clsDataArray_DataLoaded()
    
        ' Process the data in Cls_DataArray
        
    End Sub
    There is no need to check that Form3 is open when using the .Load method of the class, nor is it necessary to specifically notify Form3 from outside the class that data was loaded into it.
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •