Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316

    Unanswered: Disable a button for x seconds

    I have a form, that when loaded, a button should be disabled for x no. of seconds. Here is the code I'm using:

    Code:
    Private Sub Form_Open(Cancel As Integer)
        cmdYes.Enabled = False
    End Sub
    
    Private Sub Form_Load()
        Call Wait(3)
        cmdYes.Enabled = True
    End Sub
    I would expect this to show the form, with the button disabled, pause for 3 seconds, then enable the button. However, what is actually happening is that when the form is loaded, nothing is being shown until after 3 seconds, then the form is shown with the button enabled.

    Here is the Wait code:

    Code:
    Private Declare Sub Sleep Lib "kernel32" _
     (ByVal dwMilliseconds As Long)
    
    Public Sub Wait(Seconds As Single)
        Dim lMilliSeconds As Long
        lMilliSeconds = Seconds * 1000
        Sleep lMilliSeconds
    End Sub
    Anyone have any ideas?

  2. #2
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388

    Disable the X button

    Try this method.

    On the form using the properties for the cmdYes button in the Format Tab set Visible to FALSE.

    On the form properties in the Event Tab set the Timer Interval to 3000. 3000 is in milliseconds and equals 3 secs as each time interval is 1 millisecond.

    Still in the Event Tab put the following code in the Timer event

    Sub Form_Timer()
    cmbyes.Visible = True
    End Sub


    When the form is displayed the button is not displayed, but after 3 seconds the button is displayed.

  3. #3
    Join Date
    Jul 2002
    Location
    Island of Dots
    Posts
    316
    Cool. A bit more elegant than my initial method too. Thanks.

  4. #4
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    Your welcome.
    I also tried the wait() function a few months ago but gave up as I too had problems.

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Poppa Smurf's suggestion is a good one. The Timer is asynchronous whereas any "wait" command is syncronous. Delay procedures have their place but not for this sort of purpose.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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