Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Please Wait" popup message

Tags:

excel

vba

popup

I am trying to create a Please Wait message in Excel VBA. This is to remind the user processing a SQL query that the process is still ongoing. I would like to have this message displayed in a userform.

Currently, the user connects to SQL DB, selects database and some other options, presses Go... and the form does not unload. At the Go point I have another form which pops up with message Please Wait, but this form does not unload, i.e. the SQL execute command does not run.

My code for calling the Please Wait userform, including a label:

   Call WaitShowSQl.ExecuteCall KillWaitCall WaitShow
   SQl.Execute
   Call KillWait

In another code module I have:

   Sub WaitShow()
   Wait.Show
   End Sub

   Sub KillWait()
   Unload Wait
   End Sub

I have userform called wait with following code:

Private Sub UserForm_Activate()
Call PleaseWait
End Sub 

Sub PleaseWait()
Wait.Label1.Caption = "Calculating...Please Wait!"
End Sub

Now when executing the code, the run-time does not move back through the module in order to execute the following:

SQl.ExecuteSQl.Execute

I can show the progress of the program with a status bar, but a userform popup message would be very useful for this program.

like image 226
Fwafa Avatar asked Dec 23 '11 10:12

Fwafa


2 Answers

The default behavior of the Form.Show method is to show the form as a modal dialog. What you are looking for is a modeless dialog box, so you need to specify that, like this:

Sub WaitShow()
   Wait.Show vbModeLess
End Sub

Update:

If you can't user a modeless dialog, you have other options, as mentioned in a comment. One of them is to let the wait userform do the SQL executing. This could be done like this:

In the wait form, first declare variables

Private mySomeParameter1 As String
Private mySomeReturnValue1 As String

'Input parameters to the form
Public Sub Init(ByVal some_parameter1 As String, ...)
... Initialize your SQL, NOT execute it
End Sub

'Output values from the from
Public Sub GetReturns(ByRef some_return_value1 As String, ...)
... set the output parameters...
End Sub

'Do the work
Private Sub UserForm_Activate()
  Call PleaseWait
  'Either call DoEvents or a manual Refresh to let the label display itself
  Call ExecutSQL    ' A function that executes the SQL
  Unload Me
End Sub

And in the main form:

Sub WaitShow()
   Wait.Init(the parameters...)
   Wait.Show
   Wait.GetReturns(the results...)
End Sub

Yet another option for you would be to skip the Wait form completely and instead show an "Waiting" Image on the mainform and hide it when the SQL processing is done.

like image 178
GTG Avatar answered Oct 21 '22 09:10

GTG


Here's how to show a progress bar while your users are waiting for Excel to finish processing:

https://stackoverflow.com/a/10791349/138938

Excel progress bar

In your case, you can guess a reasonable "average" time for your queries and have the progress bar update with percentages of that time, which will reassure your users that Excel is working and they don't need to panic.

like image 34
Jon Crowell Avatar answered Oct 21 '22 09:10

Jon Crowell