Hello,
I have the need to replace some word bookmarks from my windows forms app.
I have all my word templates in my resources folder. My app is behaving as desired as long as I only open 1 word document.
If I need to click a second document, same one or different it opens word like it should, however the page is blank.
I am using the below code for each of my word documents.
Any thoughts/suggestions would be appreciated.
Thanks
LB
I have the need to replace some word bookmarks from my windows forms app.
I have all my word templates in my resources folder. My app is behaving as desired as long as I only open 1 word document.
If I need to click a second document, same one or different it opens word like it should, however the page is blank.
I am using the below code for each of my word documents.
Code:
Private Sub printEvictionNotice()
'Dim oWord As Word.Application
'Dim oDoc As Word.Document
'Bookmarks in word doc
'Address
'AmtDue
'Apt
'CityStateZip
'Date
'Owner
'Position
'Tenant
'VacateDate
Try
If chkLease() Then
fullPath = fullPath.Substring(0, fullPath.Length - 39) & "Resources\"
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add(fullPath & "Eviction Notice.doc")
'oDoc = oWord.Documents.Add("G:\Visual Studio 2010\Projects\TenantTracker2013\Resources\Eviction Notice.doc")
oDoc.Bookmarks("Date").Range.Text = Date.Now()
oDoc.Bookmarks("Apt").Range.Text = DlookUp_In_Access("Aptnumber", "Apartments", "AptId = " & Me.cboAptID.SelectedValue & "")
oDoc.Bookmarks("Address").Range.Text = DlookUp_In_Access("Address", "Properties", "PropertyId = " & Me.txtPropertyID.Text & "")
Dim strCityStateZip As String = DlookUp_In_Access("City", "Properties", "PropertyId = " & Me.txtPropertyID.Text & "") & ", " & DlookUp_In_Access("State", "Properties", "PropertyId = " & Me.txtPropertyID.Text & "") & " " & DlookUp_In_Access("ZipCode", "Properties", "PropertyId = " & Me.txtPropertyID.Text & "")
oDoc.Bookmarks("CityStateZip").Range.Text = strCityStateZip
oDoc.Bookmarks("AmtDue").Range.Text = FormatCurrency(DlookUp_In_Access("Tenantrent", "Leases", "TenantId = " & Me.txtTenantID.Text & ""))
oDoc.Bookmarks("Tenant").Range.Text = Me.txtFirstName.Text & " " & Me.txtLastName.Text
oDoc.Bookmarks("VacateDate").Range.Text = DateAdd(DateInterval.Day, 3, Date.Now)
oDoc.Bookmarks("Owner").Range.Text = My.Settings.OwnerName.ToString
oDoc.Bookmarks("Position").Range.Text = My.Settings.OwnerPosition.ToString
oDoc = Nothing
oWord = Nothing
Else
Exit Sub
End If
Catch ex As Exception
End Try
End SubThanks
LB