J
Jeffery B Paarsa
Hello all,
Following is the macro code that will be executed.
Option Explicit
Private Sub CMDPrint_Click()
' some codes....
With ActiveDocument
.Unprotect
.Bookmarks("PFName").Range _
.InsertBefore PFName
.Bookmarks("PFName").Range.Font.Color = wdColorRed
.Bookmarks("PLName").Range _
.InsertBefore PLName
.Bookmarks("PLName").Range.Font.Color = wdColorRed
ActiveDocument.Fields.Update
Application.Visible = True
NPPkg.Hide
' .PrintOut
End With
Call openMedHistory(NPPkg.PFName.Text, NPPkg.PLName.Text) '<-- Problem
End Sub
Sub openMedHistory(ByRef PFName As String, ByRef PLName As String)
WordBasic.DisableAutoMacros 1
Word.Documents.Add Template:="H:\Mdoc\(ALL)MRPMedHist.dot", Visible:=False
With ActiveDocument
' .Unprotect
.Bookmarks("PFName").Range _
.InsertBefore PFName
.Bookmarks("PFName").Range.Font.Color = wdColorRed
.Bookmarks("PLName").Range _
.InsertBefore PLName
.Bookmarks("PLName").Range.Font.Color = wdColorRed
ActiveDocument.Fields.Update
.Protect wdAllowOnlyFormFields, Noreset:=True
Application.Visible = True
End With
' WordBasic.DisableAutoMacros 0
End Sub
As you may notify I have identical two Bookmarks on these two templates
called "PFName" & "PLName". Everything is working perfect in "Sub
CMDPrint_Click()" until:
Call openMedHistory(NPPkg.PFName.Text, NPPkg.PLName.Text) '<-- Problem
As you may notice on this routine "openMedHistory" I am trying to open and
add a new document by suppressing it's Macro execution on this Template and
just populate the same fields of PFName & PLName that I have collected thru
the UserForm of NPPkg and put it on the same Bookmark fields of "PFName &
PLName" that exist on the second template/document of (ALL)MRPMedHist.doc.
Here is where the problem starts. When my both Documents are displayed if I
have entered for example "F" for PFName and "L" for PLName, data is being
duplicated on my first document like "FF" in PFName and "LL" in PLName and
the PFName & PLName on the second document "(ALL)MRPMedHist.doc" is empty. I
know I have refrencing problem on "openMedHistory" but I don't know how I
can correct that. I have used "ByVal" with no difference in the result. Any
idea?
Following is the macro code that will be executed.
Option Explicit
Private Sub CMDPrint_Click()
' some codes....
With ActiveDocument
.Unprotect
.Bookmarks("PFName").Range _
.InsertBefore PFName
.Bookmarks("PFName").Range.Font.Color = wdColorRed
.Bookmarks("PLName").Range _
.InsertBefore PLName
.Bookmarks("PLName").Range.Font.Color = wdColorRed
ActiveDocument.Fields.Update
Application.Visible = True
NPPkg.Hide
' .PrintOut
End With
Call openMedHistory(NPPkg.PFName.Text, NPPkg.PLName.Text) '<-- Problem
End Sub
Sub openMedHistory(ByRef PFName As String, ByRef PLName As String)
WordBasic.DisableAutoMacros 1
Word.Documents.Add Template:="H:\Mdoc\(ALL)MRPMedHist.dot", Visible:=False
With ActiveDocument
' .Unprotect
.Bookmarks("PFName").Range _
.InsertBefore PFName
.Bookmarks("PFName").Range.Font.Color = wdColorRed
.Bookmarks("PLName").Range _
.InsertBefore PLName
.Bookmarks("PLName").Range.Font.Color = wdColorRed
ActiveDocument.Fields.Update
.Protect wdAllowOnlyFormFields, Noreset:=True
Application.Visible = True
End With
' WordBasic.DisableAutoMacros 0
End Sub
As you may notify I have identical two Bookmarks on these two templates
called "PFName" & "PLName". Everything is working perfect in "Sub
CMDPrint_Click()" until:
Call openMedHistory(NPPkg.PFName.Text, NPPkg.PLName.Text) '<-- Problem
As you may notice on this routine "openMedHistory" I am trying to open and
add a new document by suppressing it's Macro execution on this Template and
just populate the same fields of PFName & PLName that I have collected thru
the UserForm of NPPkg and put it on the same Bookmark fields of "PFName &
PLName" that exist on the second template/document of (ALL)MRPMedHist.doc.
Here is where the problem starts. When my both Documents are displayed if I
have entered for example "F" for PFName and "L" for PLName, data is being
duplicated on my first document like "FF" in PFName and "LL" in PLName and
the PFName & PLName on the second document "(ALL)MRPMedHist.doc" is empty. I
know I have refrencing problem on "openMedHistory" but I don't know how I
can correct that. I have used "ByVal" with no difference in the result. Any
idea?