MsgBox made with wscript.shell won't close automatically in this case - forms

I am writing an .mdb file in ms-access, and with a form inside.
I've made a Subroutine to show a msgbox which will close automatically after some secs.
Sub TimedMsgBox(Message As String)
CreateObject("wscript.shell").PopUp _
Message & vbCrLf & vbCrLf & _
"This message self-closes in 2 seconds...", 2, "Message"
End Sub
When the msgbox popup, I wait and it close automatically, however, if I change my focus to other application such as firefox, the message will just wait for my attention and didn't close after the selected seconds.(i.e: it is not counting the seconds.) When I change my focus back to it, then it will count the seconds then exit.
How can I made it automatically disappear after some seconds no matter what I am doing?

If it is possible my suggestion would be to create a form instead of a msgbox. Then you can use the On Timer event on the form to automatically close after a period of time.
In my database I have a mainform that gets loaded by the users but when that form opens, I also open a hidden 'ExitForm'. This exit form has a timer event that closes the database at a certain time of night.
You might be able to do something similar.

Related

Override 'Cancel' in event procedures

There is data validation in my MS Word user form which returns the focus to the textbox where the user entered something incorrect. Now I am trying to accommodate the user's change of mind: instead of correcting the entry, I want him to be able to exit the form (click the Exit command button), in which case the entry would be discarded. I suppose that a solution would start with not using the text box's exit event. I little help from someone who knows the answer would save me a lot of testing time, perhaps to find out that I can't do it.
Does anyone know?
I understand that you are handling the Exit event of the Textbox, setting the Cancel output parameter if the data is not valid.
There's a tricky but simple solution that permits to keep that working and still have an Exit button. It permits to activate the handler of the Exit button without requiring the focus to leave the Textbox. This way you can unload the Form safely in this handler.
Try this it works pretty smoothly:
1- Set the property TakeFocusOnClick of the Exit command button to False. You can do that at design time in the property-sheet, or at run-time i.e. at UserForm_Activate
2- just unload the form when the Exit button is clicked:
Private Sub ExitButton_Click()
Unload Me
End Sub
#A.S.H provided the key to the solution below. His point is that it is possible to call another event procedure while Cancel is active in the Exit procedure of a control. That other procedure can be used to rectify the condition in the first control which is triggering the Cancel, thereby enabling an orderly exit. The all-enabling condition is that the control on whose click event the rectifying procedure is to run must not take the focus when clicked (meaning it can run without triggering an exit from the control stuck on Cancel). I have added code to the exit procedure to set CmdExit.TakeFocusOnClick = False when a Cancel condition arises there. Now, ...
Private Sub CmdExit_Click()
' 12 May 2017
' if CmdExit can't take the focus it can't be the ActiveControl
If Not ActiveControl Is CmdExit Then
Select Case ActiveControl.Name
Case "Cbx107"
Cbx107.Value = ""
Case "Tbx53"
Tbx53.Value = "0"
End Select
With CmdExit
If Not .TakeFocusOnClick Then
.TakeFocusOnClick = True
.SetFocus
End If
End With
End If
' now CmdExit is the ActiveControl
MsgMe "Cmd Exit: ActiveControl = " & ActiveControl.Name
Me.Hide
End Sub

Applescript to rule "sent mailbox zero"?

According to GTD and "inbox zero" I also wanted a corresponding "sent mailbox zero" by applying a rule in Apple Mail. (Why? Please, see the end of this question.)
Now, here is a simple Applescript solution: sortOut. How could it be more efficient?
The workflow is simply this
Loop through all sent messages that was a reply to some other message.
Get the message id of the message the sent message was a reply to.
Locate the mailbox for this (prior) message.
Any suggestions how to solve step 3 more efficiently will be appreciated, e.g. locating a mailbox directly based on message id, without having to use the message: protocol and then open the message and preferably not to code something like ... (in every mailbox) whose message id is mID which turns out to be rather slow.
tell application "Mail"
set i to 0
set mb1 to sent mailbox
repeat with m in ((messages of mb1) whose all headers contains "In-Reply-To")
set mID to content of header "In-Reply-To" of m
set cmd to "open 'message:" & mID & "'"
try
do shell script cmd
delay 1
set s to the selection
set m2 to item 1 of s
set mb2 to mailbox of m2
set mailbox of m to mb2
close front window
set i to i + 1
end try
end repeat
if i ≠ 1 then
set s to "s"
else
set s to ""
end if
set myMsg to (i & " message" & s & " moved successfully") as rich text
display notification myMsg with title "SortOut" subtitle "Sorting complete"
end tell
Some earlier discussions elsewhere indicate that some people may even wonder why I want this. My reason is simply that I like to have have all threads and conversations, concerning every project and deadline, collected together based on context.
When a project is finished I archive it as a completed entity for easy reference if I need to go back or follow up some things (e.g. when planning a yearly event, “Remember what I replied to this question last year?” That also means that all those conversations will have the same label in gmail.
So, instead of having almost 15000 sent emails in one mailbox, I now have them sorted into context based mailboxes—and the mailbox for sent messages is empty!
BTW, the Alfred workflow Mail Actions by Pedro Lobo is simply amazing for filing mail. My script sortOut does the rest ;-)
Sorry, Pedro, I didn't have enough reputation to post a link to your brilliant work.
I just updated the code but still could not locate the mailbox corresponding to a message id from the In-Reply-To header using Applescript (without the message:protocol).
tell application "Mail"
set i to 0
set mb1 to sent mailbox
repeat with m in ((messages of mb1) whose all headers contains "In-Reply-To")
set mID to content of header "In-Reply-To" of m
set cmd to "open 'message:" & mID & "'"
try
do shell script cmd
delay 1
set s to the selection
set m2 to last item of s
set mb2 to mailbox of m2
if name of mb2 does not contain "INBOX" then
set mailbox of m to mb2
close front window
set i to i + 1
end if
end try
end repeat
if i ≠ 1 then
set s to "s"
else
set s to ""
end if
set myMsg to (i & " message" & s & " moved successfully") as rich text
display notification myMsg with title "SortOut" subtitle "Sorting complete"
mb2
end tell

Is it possible to recalculate all cells (i.e. Ctrl+Shift+F9 function) automatically on a timer?

I have written functions that access off-sheet data that is prone to changing regularly. Pressing Ctrl+Shift+F9 refreshes these cells, while F9 alone does not. Is there a way to automate refreshing this data - say, once a minute?
Running libreoffice 4.4.3.2
Ok you can use a link to a value in another sheet if you like.
To create a name range insert->names->define
Sub recalc_timer
document = ThisComponent.CurrentController.Frame
switch_on = ThisComponent.NamedRanges("switched_on").ReferredCells.getCellByPosition(0,0)
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem value must be more than 0 to hold while condition
while switch_on.getValue()>0
dispatcher.executeDispatch(document, ".uno:CalculateHard", "", 0, Array())
rem wait time in milliseconds
wait 3000
wend
End Sub
*proviso
Important: Some functions may not be updated. Please test https://help.libreoffice.org/Calc/Recalculate

vb6 Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) does not work

I am trying to catch when Microsoft Windows Task Manager is closing the application. I know there are these UnloadMode possibilities:
'0 The user has chosen the Close command from the Control-menu box on the form.
'1 The Unload method has been invoked from code.
'2 The current Windows-environment session is ending.
'3 The Microsoft Windows Task Manager is closing the application.
'4 An MDI child form is closing because the MDI form is closing.
Code:
Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'[do saving]
End Sub
But it does nothing when I close application using task manager. If I close using Close button - it saves all what I need. Where is the problem?
If you terminate via the processes tab in task manager no further code gets executed whereas if you terminate via the applications tab it does.
See this answer on another forum:
By user "vbface" (2003-12-29) :
Killing a process in the Task Manager immediately (or so) kills the program where it is, with no further events firing. It is like putting an END statement in VB. No cleanup, no closing processes, just a termination of the app.
http://www.xtremevbtalk.com/showthread.php?t=131604

Messagebox.show fires twice after button click (MVVM)

I am using Galasoft MVVMLight. I have a button bound to a command which sends a message to the view to display a messagebox asking for confirmation. If I click either the Yes or No on the messagebox it performs the necessary actions then shows up again. However if I step through the program instead I only get the messagebox once. Is this a bug or is something else going on?
EDIT: I modified the messagebox.show line by adding an Icon and default result and now I can't reproduce this behavior... I'm stumped... if it happens again I'll try a counter like airplaneman19 suggested.
Try tracking the amount of times the MessageBox shows up with an integer, like so:
int counter = 0;
if(counter == 0){
MessageBox.Show();
counter++;
}
else if (counter == 1)
/*Do something that won't alter the program just to escape the if....else statement
like "x++";
I had a similar problem once, I mean, with MessageBox firing twice. It was due to focus changes, and ListView in WinForms fired another selection changed event when running the app; but when debugging - some focus change was missing, and there was no bug :)
I hope this atleast gives you some ideas...