[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

'Application is Busy' and 'Call was Rejected By Callee' Errors

Posted on 2016-07-22
11
Medium Priority
?
189 Views
Last Modified: 2016-07-22
Hello,
I am trying to do word mailmerge and I get this error.
Any suggestion on how to fix it.
I am using visual studio 2015 vb.net desktop app.
my code for mailmerge is
Public Sub CreateWordDocumentWithTableFormat(ByVal strFaxAuth As String)
        Dim objWord As Word.Application
        Dim objDoc As Word.Document
        Dim dtSQL As New DataTable
        Dim outFile As String = String.Empty
        Dim directoryName As String = String.Empty
        Dim oWord As Microsoft.Office.Interop.Word.Application
        Dim oDoc As Microsoft.Office.Interop.Word.Document
        Dim clsFrmmain As New ClsFrmMainLoad
        '           @tableName varchar(100) = null,
        '@ColumnName1 varchar(100) = null,
        '@Value varchar(100) = null

        Try
            SQL.OpenConnection()
            Dim SQLobj As New SqlCommand("WordReport")
            Dim Str_Date As String = String.Empty
            SQLobj.Parameters.AddWithValue("@tablename", "Diy")
            SQLobj.Parameters.AddWithValue("@ColumnName1 ", "FaxAuth")
            SQLobj.Parameters.AddWithValue("@Value", strFaxAuth)
            SQLobj.CommandType = CommandType.StoredProcedure
            SQLobj.Connection = SQL.GetConnection
            clsFrmmain.Populate(SQLobj)
            dtSQL = clsFrmmain.Data_Table

            If dtSQL.Rows.Count <> 0 Then


                Dim oTemplate As String = ReturnWordTemplatePath() 
                oWord = CreateObject("Word.Application")
                oWord.Visible = True
                oDoc = oWord.Documents.Add
                If IsNothing(oTemplate) = True Then
                    WordClose(oWord, oDoc)
                    Exit Sub
                End If
                oDoc = oWord.Documents.Open(oTemplate)
                
                outFile = System.IO.Path.GetFileNameWithoutExtension(oTemplate)
                outFile = outFile + str_DateToday
                directoryName = System.IO.Path.GetDirectoryName(oTemplate)
                oDoc.SaveAs2(directoryName & "\" & outFile & ".doc")
                WordClose(oWord, oDoc)
            Else
                clsFrmmain.FormatMessage(18, "", str, " Word Letter Information")
            End If

Open in new window

0
Comment
Question by:RIAS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 41724225
Which line resulted in the error ?
0
 

Author Comment

by:RIAS
ID: 41724263
If dtSQL.Rows(0)("Attn").ToString Is DBNull.Value = False Then
                    oDoc.Content.Find.Execute(FindText:="ATTN:",
                   ReplaceWith:="ATTN: " & dtSQL.Rows(0)("Attn").ToString, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll, MatchCase:=True)

it is this line in there ;dont know whether it is the matchcase causing it?
0
 

Author Comment

by:RIAS
ID: 41724281
looks like if it is not able to find FindText:="ATTN:", its giving an error.
Any workaround for this?
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 45

Expert Comment

by:AndyAinscow
ID: 41724427
Hmmm.  That line giving the problem isn't in the code you posted.  Please post the correct code.
0
 

Author Comment

by:RIAS
ID: 41724452
Public Sub CreateWordDocumentWithTableFormat(ByVal strFaxAuth As String)
        Dim objWord As Word.Application
        Dim objDoc As Word.Document
        Dim dtSQL As New DataTable
        Dim outFile As String = String.Empty
        Dim directoryName As String = String.Empty
        Dim oWord As Microsoft.Office.Interop.Word.Application
        Dim oDoc As Microsoft.Office.Interop.Word.Document
        Dim clsFrmmain As New ClsFrmMainLoad

        Try
            MySQL.OpenConnection()
            Dim SQLobj As New SqlCommand("MY_WordReport")
            Dim Str_Date As String = String.Empty
            SQLobj.Parameters.AddWithValue("@tablename", "Dry")
            SQLobj.Parameters.AddWithValue("@ColumnName1 ", "FaxAuth")
            SQLobj.Parameters.AddWithValue("@Value", strFaxAuth)
            SQLobj.CommandType = CommandType.StoredProcedure
            SQLobj.Connection = MySQL.GetConnection
            clsFrmmain.Populate(SQLobj)
            dtSQL = clsFrmmain.Data_Table

            If dtSQL.Rows.Count <> 0 Then

                Dim oTemplate As String = ReturnWordTemplatePath() '"C:nts\Fapy.doc"
                oWord = CreateObject("Word.Application")
                oWord.Visible = True
                oDoc = oWord.Documents.Add
                If IsNothing(oTemplate) = True Then
                    WordClose(oWord, oDoc)
                    Exit Sub
                End If
                oDoc = oWord.Documents.Open(oTemplate)
                If dtSQL.Rows(0)("Title").ToString Is DBNull.Value = False Then
                    oDoc.Content.Find.Execute(FindText:="TO:",
                                      ReplaceWith:="TO: " & dtSQL.Rows(0)("Title").ToString & " " & dtSQL.Rows(0)("PatientName").ToString, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll, MatchCase:=True)
                End If

                If dtSQL.Rows(0)("Attn").ToString Is DBNull.Value = False Then
                    oDoc.Content.Find.Execute(FindText:="ATTN:",
                    ReplaceWith:="ATTN: " & dtSQL.Rows(0)("Attn").ToString, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
                End If
                If dtSQL.Rows(0)("FaxNumber").ToString Is DBNull.Value = False Then
                    oDoc.Content.Find.Execute(FindText:="FAX NUMBER:",
                   ReplaceWith:="FAX NUMBER: " & dtSQL.Rows(0)("FaxNumber").ToString, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll, MatchCase:=True)
                End If
                If dtSQL.Rows(0)("Date").ToString Is DBNull.Value = False Then
                    Str_Date = clsFrmmain.ConvertDate(dtSQL.Rows(0)("Date").ToString, False)
                    oDoc.Content.Find.Execute(FindText:="DATE:",
                    ReplaceWith:="DATE: " & Str_Date, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceOne)
                End If


                If dtSQL.Rows(0)("Ref").ToString Is DBNull.Value = False Then
                    oDoc.Content.Find.Execute(FindText:="SENDER'S REFERENCE NUMBER:",
                   ReplaceWith:=" SENDER'S REFERENCE NUMBER:  " & dtSQL.Rows(0)("Ref").ToString, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll, MatchCase:=True)

                End If
                If dtSQL.Rows(0)("Comments").ToString Is DBNull.Value = False Then
                    oDoc.Content.Find.Execute(FindText:="NOTES/COMMENTS ",
                   ReplaceWith:="NOTES/COMMENTS:   " & dtSQL.Rows(0)("Comments").ToString, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll, MatchCase:=True)
                End If
                If dtSQL.Rows(0)("Date").ToString Is DBNull.Value = False Then
                    oDoc.Content.Find.Execute(FindText:="Date:",
                    ReplaceWith:="Date: " & Str_Date, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceOne, MatchCase:=True)
                End If
                If dtSQL.Rows(0)("Time").ToString Is DBNull.Value = False Then
                    oDoc.Content.Find.Execute(FindText:="At:",
                   ReplaceWith:="At: " & clsFrmmain.ConvTime(dtSQL.Rows(0)("Time").ToString), Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll, MatchCase:=True)
                End If
                If dtSQL.Rows(0)("Comments").ToString Is DBNull.Value = False Then
                    oDoc.Content.Find.Execute(FindText:="For:",
                   ReplaceWith:="For: " & dtSQL.Rows(0)("Comments").ToString, Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll, MatchCase:=True)

                End If
                Dim str_DateToday As String
                str_DateToday = clsFrmmain.ConvertDate(Date.Now, False)

                outFile = System.IO.Path.GetFileNameWithoutExtension(oTemplate)
                outFile = outFile + str_DateToday
                directoryName = System.IO.Path.GetDirectoryName(oTemplate)
                oDoc.SaveAs2(directoryName & "\" & outFile & ".doc")
                WordClose(oWord, oDoc)
            Else
                clsFrmmain.FormatMessage(18, "", strFaxAuth, " Word Letter Information")
            End If
              Catch ex As Exception
            MessageBox.Show(ex.ToString)
            Exit Sub

        End Try
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 41724458
oDoc = oWord.Documents.Open(oTemplate)
                If dtSQL.Rows(0)("Title").ToString Is DBNull.Value = False Then.....


You might want to check that oDoc is actually opened before attempting to use it.
0
 

Author Comment

by:RIAS
ID: 41724459
yes, it is open
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 41724464
oDoc = oWord.Documents.Open(oTemplate)
MsgBox.Show("wait for checking")
                If dtSQL.Rows(0)("Title").ToString Is DBNull.Value = False Then.....

Humour me please.  Try something like the above (not quite certain what the vb.net for showing a message box is of the top of my head) to make certain your code waits until the template is loaded into word.  Then click the messagebox away so your code continues.
0
 

Author Comment

by:RIAS
ID: 41724474
Andy,
That worked mate! But now how do I replace the messagebox?
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 41724513
Offhand I don't know.
Maybe there is something that will return a boolean value if the word object is busy - keep testing at one second intervals until available.

You could try using something like Sleep(1000) to make the thread wait for 1 second and hope.
0
 

Author Closing Comment

by:RIAS
ID: 41724522
Cheers mate for all your help,really appreciated!
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question