• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 545
  • Last Modified:

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
        ElseIf ComboBox1.SelectedItem = "Letter2" Then
        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.
  • 2
  • 2
  • 2
2 Solutions
Pass progressbar reference to Letter function:


In the function:

Sub Letter1(progressBar as ProgressBar)

    Do While ...
        ' do something

        progressBar.Value = ...   ' set progress bar position
        Application.DoEvents()    ' update window

End Sub
symanskiAuthor Commented:
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.

If you don't have any loop inside of Letter1 function, this is impossible. This solution works if you already have some loop, and you can update progressbar from it.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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...)
symanskiAuthor Commented:
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.Application")
        wapp.Visible = True
        With wapp.ActiveDocument.Mailmerge
        .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
With  .Datasource
         .firstrecord = Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord
         .lastrecord = Word.WdMailMergeDefaultRecord.wdDefaultLastRecord
End With
End With
Doesn't look to me you can implement a loop.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now