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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Msgbox with timer 2

Status
Not open for further replies.

Bullsandbears123

Technical User
Feb 12, 2003
291
US
I'm using the following code except I would like the msgbox to auto select the "no" button after 10 seconds. How can I do this. THANKS!!

Function checkfile()
Dim path
path = "R:\week\week_2003627_A.pdf"

If Dir(path) <> &quot;&quot; Then
Dim msg As String
Dim response As String
msg = &quot;File&quot; & path & &quot;already exists&quot; & vbCrLf & &quot;Do you want to overwrite?&quot;
response = MsgBox(msg, vbYesNo, &quot;FILE EXISTS!&quot;)

If response = vbYes Then
'do somthing
MsgBox (&quot;YES&quot;)

Else 'vbNO
'do somthine else
MsgBox (&quot;no&quot;)

End If
End If

End Function
 
One option...
Create your own message box. What I do frequently is create a generic form that I can use as a message box type of form. Thsi gives you a lot more control over the what, where and how it is used including timer control if wanted.

Good Luck
 
I really wanted to avoid making a whole new form. But I guess that's the answer. I thought there might have been a solution I did not know about. THANKS!
 
type message as caption in lable and set timer in form to make visible of lable true or false.
try!
 
Actually you can do it, but it does require some API work.
First, in the declarations section of the form, declare the following API and two form-level variables
Code:
Private Declare Function MessageBox Lib &quot;user32&quot; Alias &quot;MessageBoxA&quot; (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Dim fStr_MsgBoxTitle    As String
Dim fBol_IsTimeout      As Boolean
Then on the form, drop in the following code to activate the message box and the Timer event handler to shut it down.
Code:
Function TimeoutMessageBox(rStr_Prompt As String, rStr_Title As String, rInt_Buttons As VbMsgBoxStyle, rInt_SecondsToWait As Integer) As VbMsgBoxResult
   fStr_MsgBoxTitle = rStr_Title & Chr(160)
   Me.TimerInterval = rInt_SecondsToWait * 1000
   fBol_IsTimeout = False
   TimeoutMessageBox = MessageBox(Me.hwnd, rStr_Prompt, fStr_MsgBoxTitle, rInt_Buttons)
   Me.TimerInterval = 0
' See if we terminated via the Time out
Code:
   If (fBol_IsTimeout = True) Then
      TimeoutMessageBox = 0 ' Return a Zero if Timeout
   End If
End Function

Private Sub Form_Timer()
   Me.TimerInterval = 0
   fBol_IsTimeout = True
   AppActivate fStr_MsgBoxTitle
   SendKeys Space(1)
End Sub
The following is a simple command button that is used to start the whole process.
Code:
Private Sub cmdMaintenance_Click()
   Dim lInt_MsgBoxResponse As Integer
   Me.TimerInterval = 10000
   lInt_MsgBoxResponse = TimeoutMessageBox(&quot;Message Box Prompt&quot;, &quot;Message Box Title&quot;, vbYesNoCancel, 10)
   MsgBox lInt_MsgBoxResponse
End Sub


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
CajunCenturion,

Do you know the full name of the Timer Event tool. I looked for it under &quot;more controls&quot; but could not find it , I'm using Access XP. Thanks
 
Each Access form has a Timer automatically built in. To Activate the Timer, simply set the Interval property (0 - 65,535 milliseconds). To de-activate the timer, set the Interval property to 0. The necessary steps have already been included in the code provided.

It's different from VB where you would add Timer(s) to your forms as independant controls.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
You don't need a new form, simply add the provided into the existing form that will be active at the time you want the message box to appear.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
You're quite welcome. Glad I could help.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top