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

Locate Timed Msgbox off Dead Center? 2

Status
Not open for further replies.

pdldavis

Technical User
Oct 29, 2001
522
US
Hi, the following is some code from the Utter Access forums for creating a timed message box. It works perfectly for me and might be useful for others as well.

Option Explicit

Public Property Get oMsgBox() As Object
Set oMsgBox = CreateObject("WScript.Shell")
'// Usage: oMsgBox.PopUp "Message Text",SecondsToDisplay,"Title of Message",vbOKOnly + vbInformation
End Property

Private Sub Command1_Click()
'// This demonstrates how the Timed Message Box can be used
'// much in the way a standard message box is used
Dim mRslts

mRslts = oMsgBox.PopUp("Message Body Text", 3, "Message Title Text Goes Here", vbYesNo + vbQuestion)

If mRslts = vbYes Then

oMsgBox.PopUp "Selected Yes", 1, "Yes", vbOKOnly + vbInformation

ElseIf mRslts = vbNo Then
oMsgBox.PopUp "Selected No", 1, "No", vbOKOnly + vbInformation
Else '// message box timed out, yeilding a value of -1
oMsgBox.PopUp "Timed Out", 1, "No Selection", vbOKOnly + vbInformation
End If
End Sub

Is it possible to locate a message box created this way to someplace other than the center of the screen using Movesize, the Top property other methods?

Thanks, Dan

 
Instead of using all of that code, you can accomplish the same thing in a standard form by using the datediff function in a DO loop:

Dim timein
Dim timeout
timein=format(Now(),"Long Time")
'delay 20 seconds

Do
timeout=format(Time$,"Long Time")

If DateDiff("s", timein, timeout) > 20 Then
'close form
Docmd.close

Endif

loop



 
Thanks, that'll work for me at this time. The question remains though, can message boxes be positioned somewhere other than the center of the display?
 
You really want to go there?
There is some VB code at that centers the msgbox on the active form.
It probably needs some modifying to get to work with Access, but if you're brave enough & your application warrants the work, go for your life!

hth

Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
I do use msgBoxes but another technique is to have an invisible text box, which comes visible on an event. The advantage being that you can have it any size, any font and any colours you like.

In the Form's 'OnCurrent' Property you have

'Me.[textboxname].Visible = False'

and on the appropriate event, which can any event in the properties of the Form or any of its Objects,

'Me.[textboxname].Visible = "True".

In a totally different context, I use the same technique to cut down the number of Forms in an application by making one form do two or more jobs in different situations. For instance one of my Forms will show and ask for different information; and print it to different Reports depending on whether payment is Monthly, Quarterly or Annually, by Cheque, OnLine Banking or Paypal. Each situation is met by its own individual advice and instructions to the Client.

The Form itself will look a real "dog's dinner" in Design View and editing needs care and patience; but when you have an error there is only one place to look - and there is only one form and piece of code to amend when, inevitably, you come across an new set of circumstances.

I am sure some will like this idea, some will hate it - some will wonder why everyone isn't using it already; but I put it forward for what it is worth.
 
Actually, when I posted the delay code, I intended that it be used in a setup like HenriM is describing, i.e. you would build a form that would replace the standard message box, so that you could easly manipulate its position, etc.
 
That worked, Thanks Guys. I Ended up with a timed form whose position gets changed when needed along with the label caption depending on where it's at in the routine I'm running.

I appreciate the help,

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top