Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing Bookmark Contents in Word from Access?????????

Status
Not open for further replies.

r143r

Programmer
May 19, 2003
11
0
0
US
Hi,

I am exporting data from a form in Access to Word using Bookmarks. I am using Access 97 and Word 97. Now the exporting works fine except when the users go back in database and update the same record and try to export the currently updated record, then my code is able to find the file and bring back that file with any changes made in the Word Document (like if the clients have added graphics or anything), but the Problem is:

It concatenates all the new values with the old values on the word document.

For Example :
I have a book mark on hte word document for title, so if the title is:
Problem with Bookmarks

then when I update the same record and change the title to:

Problem With Bookmarks on Word

and try to export the updated version then it brings up the old word file like this:

Title: Problem with BookmarksProblem with Bookmarks on Word

So can anyone please help to solve this problem of concatenating these strings so that the new word document will come up like:

Title: Problem with Bookmarks on Word.

Any help will be really appreciated.

The following is the code that I am using to export the data to word:


Private Sub Command137_Click()

On Error GoTo Err_Command137_Click

Dim objWord As Object
Set objWord = CreateObject("Word.Application")

Dim WordTemplate As String
'WordTemplate = "C:\WINNT\Profiles\c62dr60\desktop\Stemp.dot"
Dim FoundFile As Boolean
'WordTemplate = "G:\RModi\updates\Stemp.dot"
'Functional Area Block
'********************************************************************************
'********************************************************************************
'CHECKING FOR AN EXISTING DOCUMENT

Dim CurWord As String
Dim ProjectNum As String
ProjectNum = Me.ReferenceNumberTxt

CurWord = "G:\RModi\updates\" & ProjectNum & ".doc"
With Application.FileSearch
.LookIn = "G:\RModi\updates\"
'.LookIn = "C:\WINNT\Profiles\c62dr60\desktop\"
.FileName = ProjectNum & ".doc"
If .Execute(SortBy:=msoSortbyFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
WordTemplate = "G:\RModi\updates\" & ProjectNum & ".doc"
'WordTemplate = "C:\WINNT\Profiles\c62dr60\desktop\Stemp.dot"
FoundFile = True
Else
'WordTemplate = "C:\WINNT\Profiles\c62dr60\desktop\Stemp.dot"

WordTemplate = "G:\RModi\updates\Stemp.dot"
MsgBox "There were no files found."
FoundFile = False
End If
End With



Dim FunctionalAreaNum As Integer
Dim strFunctional As String

'Testing Considerations Block
Dim TestingNum As Integer
Dim strTestingNone As String
Dim strMHS As String
Dim strQIPS As String
Dim strGeoAccess As String
Dim strCapitation As String
Dim strother As String
Dim strTestingAll As String

'Considerations Block
Dim strConsAll As String
Dim strConsNone As String
Dim strConsMHS As String
Dim strConsHipaa As String
Dim strConsOptimed As String
Dim strConsCorp As String
Dim strConsProv As String
Dim strConsSliq As String
Dim strConsEcom As String
Dim strConsPlanmate As String
Dim ConsidOther As String

Dim DB As Database
Set DB = CurrentDb
Dim Quote As String
Quote = Chr$(34)
'Implementation CheckList Block
Dim strImplAll As String
Dim strProgName As String
Dim strProj As String
Dim ImplOther As String
Dim CreatedBy As Recordset
Set CreatedBy = DB.OpenRecordset("SELECT SOWCreatedByTable.CreatedBy From SOWCreatedByTable Where SOWCreatedByTable.[Project#] = " & Quote & Me.ReferenceNumberTxt & Quote & " AND SOWCreatedByTable.[Version] = " & Me.VersionNumberTxt & ";")
Dim strCreatedBy As String


If FoundFile = True Then

With CreatedBy
Do While Not .EOF

If strCreatedBy = "" Then
strCreatedBy = CreatedBy.Fields(0)
ElseIf strCreatedBy <> &quot;&quot; Then
strCreatedBy = strCreatedBy & vbCrLf & _
CreatedBy.Fields(0)
End If

.MoveNext
Loop
End With

With objWord
.Visible = True
.Documents.Open (WordTemplate)
.ActiveDocument.Bookmarks(&quot;RefNumber&quot;).Select
.Selection.text = (CStr(Me.ReferenceNumberTxt & vbNullString))
.ActiveDocument.Bookmarks(&quot;Version&quot;).Select
.Selection.text = (CStr(Me.VersionNumberTxt & vbNullString))
.ActiveDocument.Bookmarks(&quot;Activity&quot;).Select
.Selection.text = (CStr(Me.Activity & vbNullString))
.ActiveDocument.Bookmarks(&quot;Assumptions&quot;).Select
.Selection.text = (CStr(Me.Assumptions & vbNullString))
.ActiveDocument.Bookmarks(&quot;CostDescription&quot;).Select
.Selection.text = (CStr(Me.CostDescription & vbNullString))
.ActiveDocument.Bookmarks(&quot;CreatedBy&quot;).Select
.Selection.text = (CStr(strCreatedBy & vbNullString))
.ActiveDocument.Bookmarks(&quot;CreationDate&quot;).Select
.Selection.text = (CStr(Me.CreateDate & vbNullString))
.ActiveDocument.Bookmarks(&quot;EndResearch&quot;).Select
.Selection.text = (CStr(Me.EndResearch & vbNullString))
.ActiveDocument.Bookmarks(&quot;ISLead&quot;).Select
.Selection.text = (CStr(Me.ISLeadCmb & vbNullString))
.ActiveDocument.Bookmarks(&quot;RequestName&quot;).Select
.Selection.text = (CStr(Me.RequestNameTxt & vbNullString))
.ActiveDocument.Bookmarks(&quot;RevisionDate&quot;).Select
.Selection.text = (CStr(Me.RevisionDate & vbNullString))
.ActiveDocument.Bookmarks(&quot;Scope&quot;).Select
.Selection.text = (CStr(Me.ScopeTxt & vbNullString))
.ActiveDocument.Bookmarks(&quot;ServiceRequestDate&quot;).Select
.Selection.text = (CStr(Me.ServiceRequestDateTxt & vbNullString))
.ActiveDocument.Bookmarks(&quot;StartActive&quot;).Select
.Selection.text = (CStr(Me.StartActive & vbNullString))
.ActiveDocument.Bookmarks(&quot;StartResearch&quot;).Select
.Selection.text = (CStr(Me.StartResearch & vbNullString))
.ActiveDocument.Bookmarks(&quot;SystemComplete&quot;).Select
.Selection.text = (CStr(Me.SystemTestComplete & vbNullString))
FunctionalAreaNum = FunctionalAreaTxt
If FunctionalAreaNum = 1 Then
strFunctional = &quot;Professional Only&quot;
ElseIf FunctionalAreaNum = 2 Then
strFunctional = &quot;Institutional Only&quot;
ElseIf FunctionalAreaNum = 3 Then
strFunctional = &quot;Professional and Institutional&quot;
End If
.ActiveDocument.Bookmarks(&quot;FunctionalArea&quot;).Select
.Selection.text = (CStr(strFunctional & vbNullString))

'******************Testing Considerations Block *******************************

If Me!TestingConsNone.Value = True Then
strTestingNone = &quot;None&quot; & vbCrLf
ElseIf Me!TestingConsNone.Value = False Then
strTestingNone = &quot;&quot;
End If
If Me!TestingConsMHS.Value = True Then
strMHS = &quot;MHS&quot; & vbCrLf
ElseIf Me!TestingConsMHS.Value = False Then
strMHS = &quot;&quot;
End If
If Me!TestingConsQIPS.Value = True Then
strQIPS = &quot;QIPS&quot; & vbCrLf
ElseIf Me!TestingConsQIPS.Value = False Then
strQIPS = &quot;&quot;
End If
If Me!TestingConsCapitation.Value = True Then
strCapitation = &quot;Capitation&quot; & vbCrLf
ElseIf Me!TestingConsCapitation.Value = False Then
strCapitation = &quot;&quot;
End If
If Me!TestingConsGEOAccess.Value = True Then
strGeoAccess = &quot;GeoAccess&quot; & vbCrLf
Else
strGeoAccess = &quot;&quot;
End If
If Me!TestingOtherChk.Value = True Then
strother = &quot;OTHER: &quot; & Me!TestingConsiderationsOther
strTestingAll = strTestingNone & strMHS & strQIPS & strCapitation & strGeoAccess & strother
ElseIf Me!TestingOtherChk.Value = False Then
strother = &quot;&quot;
strTestingAll = strTestingNone & strMHS & strQIPS & strCapitation & strGeoAccess
End If
.ActiveDocument.Bookmarks(&quot;TestingCons&quot;).Select
.Selection.text = (CStr(strTestingAll & vbNullString))

'******************Considerations Block *******************************

If Me!ConsiderationsNone.Value = True Then
strConsNone = &quot;None&quot; & vbCrLf
ElseIf Me!ConsiderationsNone.Value = False Then
strConsNone = &quot;&quot;
End If
If Me!ConsiderationsMHS.Value = True Then
strConsMHS = &quot;MHS Interface&quot; & vbCrLf
ElseIf Me!ConsiderationsMHS.Value = False Then
strConsMHS = &quot;&quot;
End If
If Me!ConsiderationsOptimed.Value = True Then
strConsOptimed = &quot;Optimed&quot; & vbCrLf
ElseIf Me!ConsiderationsOptimed.Value = False Then
strConsOptimed = &quot;&quot;
End If
If Me!ConsiderationsCorpDataWrhse.Value = True Then
strConsCorp = &quot;Corporate Data Warehouse&quot; & vbCrLf
ElseIf Me!ConsiderationsCorpDataWrhse.Value = False Then
strConsCorp = &quot;&quot;
End If
If Me!ConsiderationsProviderDir.Value = True Then
strConsProv = &quot;Provider Directory&quot; & vbCrLf
Else
strConsProv = &quot;&quot;
End If
If Me!ConsiderationsSLIQ.Value = True Then
strConsSliq = &quot;SLIQ&quot; & vbCrLf
Else
strConsSliq = &quot;&quot;
End If
If Me!ConsiderationsHIPAA.Value = True Then
strConsHipaa = &quot;HIPAA&quot; & vbCrLf
Else
strConsHipaa = &quot;&quot;
End If
If Me!ConsiderationsECommerce.Value = True Then
strConsEcom = &quot;ECommerce&quot; & vbCrLf
Else
strConsEcom = &quot;&quot;
End If
If Me!ConsiderationsPlanmate.Value = True Then
strConsPlanmate = &quot;Planmate&quot; & vbCrLf
Else
strConsPlanmate = &quot;&quot;
End If
If Me!ConsiderationsOtherChk.Value = True Then
ConsidOther = &quot;OTHER: &quot; & Me!ConsiderationsOther
strConsAll = strConsNone & strConsMHS & strConsOptimed & strConsCorp & strConsProv & strConsSliq & strConsEcom & strConsPlanmate & ConsidOther
ElseIf Me!ConsiderationsOtherChk.Value = False Then
ConsidOther = &quot;&quot;
strConsAll = strConsNone & strConsMHS & strConsOptimed & strConsCorp & strConsProv & strConsSliq & strConsEcom & strConsPlanmate & ConsidOther
End If
.ActiveDocument.Bookmarks(&quot;Considerations&quot;).Select
.Selection.text = (CStr(strConsAll & vbNullString))

'******************Implementation Block *******************************
If Me!ProgramNameChk.Value = True Then
strProgName = &quot;Program: &quot; & Me!ImplChecklistProgramName & vbCrLf
Else
strProgName = &quot;&quot;
End If
If Me!ImplChecklistProjanChk.Value = True Then
strProj = &quot;Program Names Added to Projan&quot; & vbCrLf
Else
strProj = &quot;&quot;
End If
If Me!ImplOtherChk.Value = True Then
ImplOther = &quot;Other: &quot; & Me!ImplChecklistOther & vbCrLf
Else
ImplOther = &quot;&quot;
End If
strImplAll = strProgName & strProj & ImplOther
.ActiveDocument.Bookmarks(&quot;Implementation&quot;).Select
.Selection.text = (CStr(strImplAll & vbNullString))

End With

Else
With CreatedBy
Do While Not .EOF

If strCreatedBy = &quot;&quot; Then
strCreatedBy = CreatedBy.Fields(0)
ElseIf strCreatedBy <> &quot;&quot; Then
strCreatedBy = strCreatedBy & vbCrLf & _
CreatedBy.Fields(0)
End If

.MoveNext
Loop
End With

With objWord
.Visible = True
.Documents.Add (WordTemplate)
.ActiveDocument.Bookmarks(&quot;RefNumber&quot;).Select
.Selection.text = (CStr(Me.ReferenceNumberTxt & vbNullString))
.ActiveDocument.Bookmarks(&quot;Version&quot;).Select
.Selection.text = (CStr(Me.VersionNumberTxt & vbNullString))
.ActiveDocument.Bookmarks(&quot;Activity&quot;).Select
.Selection.text = (CStr(Me.Activity & vbNullString))
.ActiveDocument.Bookmarks(&quot;Assumptions&quot;).Select
.Selection.text = (CStr(Me.Assumptions & vbNullString))
.ActiveDocument.Bookmarks(&quot;CostDescription&quot;).Select
.Selection.text = (CStr(Me.CostDescription & vbNullString))
.ActiveDocument.Bookmarks(&quot;CreatedBy&quot;).Select
.Selection.text = (CStr(strCreatedBy & vbNullString))
.ActiveDocument.Bookmarks(&quot;CreationDate&quot;).Select
.Selection.text = (CStr(Me.CreateDate & vbNullString))
.ActiveDocument.Bookmarks(&quot;EndResearch&quot;).Select
.Selection.text = (CStr(Me.EndResearch & vbNullString))
.ActiveDocument.Bookmarks(&quot;ISLead&quot;).Select
.Selection.text = (CStr(Me.ISLeadCmb & vbNullString))
.ActiveDocument.Bookmarks(&quot;RequestName&quot;).Select
.Selection.text = (CStr(Me.RequestNameTxt & vbNullString))
.ActiveDocument.Bookmarks(&quot;RevisionDate&quot;).Select
.Selection.text = (CStr(Me.RevisionDate & vbNullString))
.ActiveDocument.Bookmarks(&quot;Scope&quot;).Select
.Selection.text = (CStr(Me.ScopeTxt & vbNullString))
.ActiveDocument.Bookmarks(&quot;ServiceRequestDate&quot;).Select
.Selection.text = (CStr(Me.ServiceRequestDateTxt & vbNullString))
.ActiveDocument.Bookmarks(&quot;StartActive&quot;).Select
.Selection.text = (CStr(Me.StartActive & vbNullString))
.ActiveDocument.Bookmarks(&quot;StartResearch&quot;).Select
.Selection.text = (CStr(Me.StartResearch & vbNullString))
.ActiveDocument.Bookmarks(&quot;SystemComplete&quot;).Select
.Selection.text = (CStr(Me.SystemTestComplete & vbNullString))
FunctionalAreaNum = FunctionalAreaTxt
If FunctionalAreaNum = 1 Then
strFunctional = &quot;Professional Only&quot;
ElseIf FunctionalAreaNum = 2 Then
strFunctional = &quot;Institutional Only&quot;
ElseIf FunctionalAreaNum = 3 Then
strFunctional = &quot;Professional and Institutional&quot;
End If
.ActiveDocument.Bookmarks(&quot;FunctionalArea&quot;).Select
.Selection.text = (CStr(strFunctional & vbNullString))

'******************Testing Considerations Block *******************************

If Me!TestingConsNone.Value = True Then
strTestingNone = &quot;None&quot; & vbCrLf
ElseIf Me!TestingConsNone.Value = False Then
strTestingNone = &quot;&quot;
End If
If Me!TestingConsMHS.Value = True Then
strMHS = &quot;MHS&quot; & vbCrLf
ElseIf Me!TestingConsMHS.Value = False Then
strMHS = &quot;&quot;
End If
If Me!TestingConsQIPS.Value = True Then
strQIPS = &quot;QIPS&quot; & vbCrLf
ElseIf Me!TestingConsQIPS.Value = False Then
strQIPS = &quot;&quot;
End If
If Me!TestingConsCapitation.Value = True Then
strCapitation = &quot;Capitation&quot; & vbCrLf
ElseIf Me!TestingConsCapitation.Value = False Then
strCapitation = &quot;&quot;
End If
If Me!TestingConsGEOAccess.Value = True Then
strGeoAccess = &quot;GeoAccess&quot; & vbCrLf
Else
strGeoAccess = &quot;&quot;
End If
If Me!TestingOtherChk.Value = True Then
strother = &quot;OTHER: &quot; & Me!TestingConsiderationsOther
strTestingAll = strTestingNone & strMHS & strQIPS & strCapitation & strGeoAccess & strother
ElseIf Me!TestingOtherChk.Value = False Then
strother = &quot;&quot;
strTestingAll = strTestingNone & strMHS & strQIPS & strCapitation & strGeoAccess
End If
.ActiveDocument.Bookmarks(&quot;TestingCons&quot;).Select
.Selection.text = (CStr(strTestingAll & vbNullString))

'******************Considerations Block *******************************

If Me!ConsiderationsNone.Value = True Then
strConsNone = &quot;None&quot; & vbCrLf
ElseIf Me!ConsiderationsNone.Value = False Then
strConsNone = &quot;&quot;
End If
If Me!ConsiderationsMHS.Value = True Then
strConsMHS = &quot;MHS Interface&quot; & vbCrLf
ElseIf Me!ConsiderationsMHS.Value = False Then
strConsMHS = &quot;&quot;
End If
If Me!ConsiderationsOptimed.Value = True Then
strConsOptimed = &quot;Optimed&quot; & vbCrLf
ElseIf Me!ConsiderationsOptimed.Value = False Then
strConsOptimed = &quot;&quot;
End If
If Me!ConsiderationsCorpDataWrhse.Value = True Then
strConsCorp = &quot;Corporate Data Warehouse&quot; & vbCrLf
ElseIf Me!ConsiderationsCorpDataWrhse.Value = False Then
strConsCorp = &quot;&quot;
End If
If Me!ConsiderationsProviderDir.Value = True Then
strConsProv = &quot;Provider Directory&quot; & vbCrLf
Else
strConsProv = &quot;&quot;
End If
If Me!ConsiderationsSLIQ.Value = True Then
strConsSliq = &quot;SLIQ&quot; & vbCrLf
Else
strConsSliq = &quot;&quot;
End If
If Me!ConsiderationsHIPAA.Value = True Then
strConsHipaa = &quot;HIPAA&quot; & vbCrLf
Else
strConsHipaa = &quot;&quot;
End If
If Me!ConsiderationsECommerce.Value = True Then
strConsEcom = &quot;ECommerce&quot; & vbCrLf
Else
strConsEcom = &quot;&quot;
End If
If Me!ConsiderationsPlanmate.Value = True Then
strConsPlanmate = &quot;Planmate&quot; & vbCrLf
Else
strConsPlanmate = &quot;&quot;
End If
If Me!ConsiderationsOtherChk.Value = True Then
ConsidOther = &quot;OTHER: &quot; & Me!ConsiderationsOther
strConsAll = strConsNone & strConsMHS & strConsOptimed & strConsCorp & strConsProv & strConsSliq & strConsEcom & strConsPlanmate & ConsidOther
ElseIf Me!ConsiderationsOtherChk.Value = False Then
ConsidOther = &quot;&quot;
strConsAll = strConsNone & strConsMHS & strConsOptimed & strConsCorp & strConsProv & strConsSliq & strConsEcom & strConsPlanmate & ConsidOther
End If
.ActiveDocument.Bookmarks(&quot;Considerations&quot;).Select
.Selection.text = (CStr(strConsAll & vbNullString))

'******************Implementation Block *******************************
If Me!ProgramNameChk.Value = True Then
strProgName = &quot;Program: &quot; & Me!ImplChecklistProgramName & vbCrLf
Else
strProgName = &quot;&quot;
End If
If Me!ImplChecklistProjanChk.Value = True Then
strProj = &quot;Program Names Added to Projan&quot; & vbCrLf
Else
strProj = &quot;&quot;
End If
If Me!ImplOtherChk.Value = True Then
ImplOther = &quot;Other: &quot; & Me!ImplChecklistOther & vbCrLf
Else
ImplOther = &quot;&quot;
End If
strImplAll = strProgName & strProj & ImplOther
.ActiveDocument.Bookmarks(&quot;Implementation&quot;).Select
.Selection.text = (CStr(strImplAll & vbNullString))



End With
End If

'End if

Exit_Command137_Click:
Exit Sub

Err_Command137_Click:
MsgBox Err.Description
Resume Exit_Command137_Click



End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top