Cant create Object for SetTimeout method

Posted on 2006-05-04
Last Modified: 2012-06-27
I am currently working in Outlook 2003 code behind the forms. This is vbscript based. When I try to run the following snippet of code behind the form I get the following:

 Microsoft VBScript runtime error: Object required: 'windows'

    Dim dtmStartTime

    Sub Test()
        dtmStartTime = Now
        idTimer = windows.setTimeout("PausedSection", 5000, "VBScript")
    End Sub

    Sub PausedSection()
        Msgbox dtmStartTime & vbCrLf & Now
    End Sub

Keep in mind that I am trying to run this in an outlook form. I want to know how to create an object for the setTimout method above. I would even be willing to except an object creation for Wscript.Sleep, but I had no luck with that either as the objects are not readily exposed under outlooks code behind the form. I hope that I have explained enough.
Question by:BLACK THANOS
    LVL 3

    Expert Comment

    is idTimer an object? a variable?
    Is Windows an object, a control?

    assuming Windows and idTimer are objects you need the SET keyword:

    SET idTimer = windows.setTimeout("PausedSection", 5000, "VBScript")

    the wscript sleep isn't available to the VB IDE to my knowledge, use the sleep API:

    Paste the following line at the top of your code/module (right under "option explicit" if it's there:
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    then in your code call it up:

    Sleep 5000

    which is 5 seconds

    LVL 17

    Expert Comment

    idTimer = windows.setTimeout("PausedSection", 5000, "VBScript")

    should be

     idTimer = window.setTimeout("PausedSection", 5000, "VBScript")

    Author Comment

    Great responses guys, but not quite what I am looking for. The code that you specified above will not work in outlook forms unless an object is created. Outlook behind the forms is looking for an object to be created. For instance:

    Set objApp = CreateObject("Word.Application")
    Set objApp = CreateObject("Excel.Application")  

    exposes the Word and Excel objects in Outlook so the methods are accessible. I was presuming that there would be something to the effect like : set objApp = Createobject("Window.Application) to expose the SetTimeout method. I hope this makes sense.
    LVL 3

    Accepted Solution

    I assure you this works as I just tried it in an Outlook VBA IDE:

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    That line needs to be placed at the top of whatever you are coding, be it class, module or form.  You can also make this call global by changing the scope and inserting it into a module:

    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    To call it up just use:

    Sleep 5000


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    779 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