Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to delay a process? 3

Status
Not open for further replies.

emailswe

Technical User
Aug 20, 2007
9
SE
Hi

Anyone has a tip how to smoothley create a msgbox to either start or stop the process at startup of a scheduled task. AND the main q, how to activate the process if neither option i chosen. This is since the proces is atomatically ran during nigths, bu I would like to have an option to manually run it or stop the process more easily than ctrl+break
 
emailswe,

Under which application is the task running?

----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
WalkerEvans
under exel its a quite simple auto report generator in wich I sometimes need to do som changes.

Cheers
 
emailswe,

Sorry it's taken so long to get back to you; I'm in the midst of testing a massive new program, one module at a time, and getting back here quick isn't always possible.

As for the first problem, the following code placed at the start of the module should handle the message box:

Code:
Private Sub Workbook_Open()
Dim Msg, Style, Title, Response
Msg = "Continue to run this process?"
Style = vbYesNo + vbInformation + vbDefaultButton2
Title = "CHOOSE EITHER YES OR NO"
Response = MsgBox(Msg, Style, Title)
    If Response = vbYes Then
        'your stuff
    Else
        'your stuff
    End If
End Sub

NOTE: This must be placed in the ThisWorkbook module. It will run automatically when the workbook is opened (which I am presuming is the starting point of your process - if not, some tweaking will be in order).

The second part of your problem (starting the process if no option is chosen) would seem to be best handled by a timer … if no response is received within “X” amount of time, it automatically runs. See thread707-1399412 for an elegant solution to that problem.

I'll check back again later.

----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
WalkerEvans,

I really appreciate you help. But I cant get the damn "timer" to "time" the msgbox.

Could you (or anyone else who are interested) please help me again?

Cheers
 
This may be of help, a message box with built in timer:
Code:
Option Explicit

Private Declare Function MessageBoxTimeOut Lib "user32" _
Alias "MessageBoxTimeoutA" (ByVal hWnd As Long, _
ByVal lpText As String, ByVal lpCaption As String, _
ByVal uType As VbMsgBoxStyle, ByVal wLanguageId As Long, _
ByVal dwMilliseconds As Long) As Long

Private Sub Command1_Click()
    MessageBoxTimeOut 0&, "Disappearing Msgbox", "Soon Be Gone", vbInformation, 0&, 2000
    
End Sub

Everybody body is somebodys Nutter.
 
That API from Chris works a treat. I'm sure to use that in the future --> have a *

The reason why you can't use a timer with a normal msgbox is that the msgbox is modal. It stalls your code untill a response is given. Use can create a userform that functions as a msgbox and put the timer in the userform_activate event if you don't want to resort to API.

Cheers,

Roel
 
ClulessChris,

This is certainly more elegant than my approach. BTW, I didn't mean for the timer to be run as a separate, standalone function ... it was to be incorporated into the Private sub. Then, if the timer ran out the default action would have been to "push" the Yes button. I once again fell into the trap of presuming others would see things the same way I do. I'm going to embarrass myself clear off this site if that isn't corrected.

May that as it may, your approach attains the same result with less code. Have a purple pointy thing (*) from me as well!

----------------------------------------------------------------------------------
"A committee is a life form with six or more legs and no brain." -- L. Long
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top