Error! Reference source not found.

B

Bryan

Hi all.
I am having a very puzzling issue with Ref. I have one field in my document
that repeats. I should be able to just use a ref that gets its info from my
bookmark. Well, it does... sort of. I am using message boxes to fill in the
doc and then it prints. When I look at my screen, the info is correct, but
my printed copy always says, "Error! Reference source not found." where my
ref is. I am using an ActiveDocument.Fields.Update before my printout
command, but have not been successful. Any ideas?
 
J

Jean-Guy Marcil

Bryan was telling us:
Bryan nous racontait que :
Hi all.
I am having a very puzzling issue with Ref. I have one field in my
document that repeats. I should be able to just use a ref that gets
its info from my bookmark. Well, it does... sort of. I am using
message boxes to fill in the doc and then it prints. When I look at
my screen, the info is correct, but my printed copy always says,
"Error! Reference source not found." where my ref is. I am using an
ActiveDocument.Fields.Update before my printout command, but have not
been successful. Any ideas?

Tell us exactly what is the content of the bookmark that the REF field is
pointing towards (as well as the bookmark name itself), and then post the
REF field code you are using.

What Word version?
 
B

Bryan

Bookmark content: either 480 or 230
Bookmark Name: Voltage
Ref Voltage

Also, below is my macro. I've a feeling it is a timing issue, but am not
sure how to fix it.

Sub AutoOpen()

' Serialize Macro
' Macro recorded 06/12/2009 by Bryan Daniels
Dim Message As String, Title As String, Default As String, NumCopies As Long
Dim Rng1 As Range, SerialNumber As Long, Counter As Long, Config As String,
PPONumber As Long
Dim ULLabelPrefix As String, ULLabel As Long, Voltage As String

' Set prompt.
Message = "Enter the number of copies that you want to print"
'Set title.
Title = "Print"
'Set default.
Default = "1"

' Display message, title, and default value for PPO Number.
NumCopies = Val(InputBox(Message, Title, Default))
If NumCopies = Cancel Then End
Message = "Enter the PPO Number"
Title = "PPO Number"
PPONumber = Val(InputBox(Message, Title, ""))

' Display message, title, and default value for Serial Number.
Message = "Enter the starting Serial Number"
Title = "Serial Number"
SerialNumber = Val(InputBox(Message, Title, ""))

' Display message, title, and default value for UL Label Prefix.
Message = "Enter the UL Label Prefix (2 Letters)"
Title = "UL Label Prefix"
ULLabelPrefix = InputBox(Message, Title, "")

' Display message, title, and default value for UL Label.
Message = "Enter the starting UL Label number (NUMBERS ONLY!)"
Title = "UL Label"
ULLabel = Val(InputBox(Message, Title, ""))

' Display message, title, and default value for configuration.
Message = "Enter the configuration number."
Title = "Configuration Number"
Config = InputBox(Message, Title, "")

' Display message, title, and default value for Voltage.
Message = "Enter the line Voltage."
Title = "Line Voltage"
Voltage = Val(InputBox(Message, Title, ""))

Documents("MPL99910014.doc").Activate

ActiveDocument.Fields.Update

Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range
Counter = 0

Set Rng2 = ActiveDocument.Bookmarks("Config").Range

Set Rng3 = ActiveDocument.Bookmarks("PPONumber").Range

Set Rng4 = ActiveDocument.Bookmarks("ULLabel").Range
Counter = 0

Set Rng5 = ActiveDocument.Bookmarks("ULLabelPrefix").Range

Set Rng6 = ActiveDocument.Bookmarks("Voltage").Range

ActiveDocument.Fields.Update

While Counter < NumCopies
Rng1.Delete
Rng2.Delete
Rng3.Delete
Rng4.Delete
Rng5.Delete
Rng6.Delete

Rng1.Text = Format(SerialNumber, "00000000")
Rng2.Text = Config
Rng3.Text = PPONumber
Rng4.Text = Format(ULLabel, "000000")
Rng5.Text = Format(ULLabelPrefix, ">")
Rng6.Text = Voltage

ActiveDocument.Fields.Update

ActiveDocument.PrintOut
SerialNumber = SerialNumber + 1
ULLabel = ULLabel + 1
Counter = Counter + 1
Wend

'Recreate the bookmark ready for the next use.
With ActiveDocument.Bookmarks
..Add Name:="SerialNumber", Range:=Rng1
..Add Name:="Config", Range:=Rng2
..Add Name:="PPONumber", Range:=Rng3
..Add Name:="ULLabel", Range:=Rng4
..Add Name:="ULLabelPrefix", Range:=Rng5
..Add Name:="Voltage", Range:=Rng6

End With
'Next line added to update { REF SerialNumber }
Dim Fld As Field
For Each Fld In ActiveDocument.Fields
If Fld.Type = wdFieldRef Then Fld.Update
Next

End Sub

Thx, Bryan
 
J

Jean-Guy Marcil

Bryan was telling us:
Bryan nous racontait que :
Bookmark content: either 480 or 230
Bookmark Name: Voltage
Ref Voltage

Also, below is my macro. I've a feeling it is a timing issue, but am
not sure how to fix it.

Sub AutoOpen()

' Serialize Macro
' Macro recorded 06/12/2009 by Bryan Daniels
Dim Message As String, Title As String, Default As String, NumCopies
As Long Dim Rng1 As Range, SerialNumber As Long, Counter As Long,
Config As String, PPONumber As Long
Dim ULLabelPrefix As String, ULLabel As Long, Voltage As String

' Set prompt.
Message = "Enter the number of copies that you want to print"
'Set title.
Title = "Print"
'Set default.
Default = "1"

' Display message, title, and default value for PPO Number.
NumCopies = Val(InputBox(Message, Title, Default))
If NumCopies = Cancel Then End
Message = "Enter the PPO Number"
Title = "PPO Number"
PPONumber = Val(InputBox(Message, Title, ""))

' Display message, title, and default value for Serial Number.
Message = "Enter the starting Serial Number"
Title = "Serial Number"
SerialNumber = Val(InputBox(Message, Title, ""))

' Display message, title, and default value for UL Label Prefix.
Message = "Enter the UL Label Prefix (2 Letters)"
Title = "UL Label Prefix"
ULLabelPrefix = InputBox(Message, Title, "")

' Display message, title, and default value for UL Label.
Message = "Enter the starting UL Label number (NUMBERS ONLY!)"
Title = "UL Label"
ULLabel = Val(InputBox(Message, Title, ""))

' Display message, title, and default value for configuration.
Message = "Enter the configuration number."
Title = "Configuration Number"
Config = InputBox(Message, Title, "")

' Display message, title, and default value for Voltage.
Message = "Enter the line Voltage."
Title = "Line Voltage"
Voltage = Val(InputBox(Message, Title, ""))

Documents("MPL99910014.doc").Activate

ActiveDocument.Fields.Update

Set Rng1 = ActiveDocument.Bookmarks("SerialNumber").Range
Counter = 0

Set Rng2 = ActiveDocument.Bookmarks("Config").Range

Set Rng3 = ActiveDocument.Bookmarks("PPONumber").Range

Set Rng4 = ActiveDocument.Bookmarks("ULLabel").Range
Counter = 0

Set Rng5 = ActiveDocument.Bookmarks("ULLabelPrefix").Range

Set Rng6 = ActiveDocument.Bookmarks("Voltage").Range

ActiveDocument.Fields.Update

While Counter < NumCopies
Rng1.Delete
Rng2.Delete
Rng3.Delete
Rng4.Delete
Rng5.Delete
Rng6.Delete

Above. you set each range to point to a bookmark, then, when you delete the
range, you delete the bookmark, however, in the next set of instructions,
you do insert text at each range, but the bookmarks are gone.
I am not sure why you delete the range...
Just replace each Range.Text by the value you want

If you need to re-establish the bookmark, create a function that you will
call.
Pass the text value and the bookmark name:

Function SetBookmarkText(strValue As String, strName As String)

dim rgeBook As Range

Set rgeBook = ActiveDocument.Bookmarks(strName).Range
rgeBook.Text = strValue

ActiveDocument.Bookmarks.Add strName, rgeBook

End Function


And call it like this:

SetBookmarkText ULLabelPrefix, ULLabelPrefix
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top