symanski
asked on
Implementing a progressbar in VB.NET
I want to implement a progressbar to show the mail merge progress after a user has selected a letter from a combobox on Form1. My script so far as follows:
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
If ComboBox1.SelectedItem = "Letter1" Then
Module1.Letter1()
ElseIf ComboBox1.SelectedItem = "Letter2" Then
Module1.Letter2()
End If
*Module1 contains the mail merge script
I want the progress bar to move on Form1 while the mail merge (Module1) is executing. I would appreciate any solutions as this is my first VB.net project.
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
If ComboBox1.SelectedItem = "Letter1" Then
Module1.Letter1()
ElseIf ComboBox1.SelectedItem = "Letter2" Then
Module1.Letter2()
End If
*Module1 contains the mail merge script
I want the progress bar to move on Form1 while the mail merge (Module1) is executing. I would appreciate any solutions as this is my first VB.net project.
ASKER
I'm still having problems with the 'Do While' statement in the letters function. Would I need to use a loop to update the progressbar until the mail merge was completed.
Any suggestions would be appreciated.
Thanks
Any suggestions would be appreciated.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you don't have a loop and you want to display something that will make the user understand that the computer
is working, display some kind of form with a timer on it, that will change an icon every 1 second...
Like the compying progress window of windows (2 folders with files moving between, and some wrong calculation of the
time remaining...)
is working, display some kind of form with a timer on it, that will change an icon every 1 second...
Like the compying progress window of windows (2 folders with files moving between, and some wrong calculation of the
time remaining...)
ASKER
Is there any way of implementing a loop into the existing module below:
Sub Letter1(ByVal progressBar As ProgressBar)
Dim wapp As Word.Application
wapp = CreateObject("Word.Applica tion")
wapp.Documents.Open("path. ..")
wapp.Visible = True
With wapp.ActiveDocument.Mailme rge
.Destination = Word.WdMailMergeDestinatio n.wdSendTo NewDocumen t
With .Datasource
.firstrecord = Word.WdMailMergeDefaultRec ord.wdDefa ultFirstRe cord
.lastrecord = Word.WdMailMergeDefaultRec ord.wdDefa ultLastRec ord
End With
.execute(pause:=False)
End With
wapp.Windows.Item("Letter1 .doc").Clo se()
Sub Letter1(ByVal progressBar As ProgressBar)
Dim wapp As Word.Application
wapp = CreateObject("Word.Applica
wapp.Documents.Open("path.
wapp.Visible = True
With wapp.ActiveDocument.Mailme
.Destination = Word.WdMailMergeDestinatio
With .Datasource
.firstrecord = Word.WdMailMergeDefaultRec
.lastrecord = Word.WdMailMergeDefaultRec
End With
.execute(pause:=False)
End With
wapp.Windows.Item("Letter1
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Module1.Letter1(progressBa
In the function:
Sub Letter1(progressBar as ProgressBar)
Do While ...
' do something
progressBar.Value = ... ' set progress bar position
Application.DoEvents() ' update window
End
End Sub