Automating Seq Field Code Ticket Numbering

C

Craig

I am trying to automate the numbering of tickets for a youth centre
fundraiser. There are 3 tickets on one page. I found an article in PCPlus by
Helen Bradley on using numbering tickets and ticket stubs using field code
sequential numbering which works fine. However, I wanted to create a macro
that would automate this portion: "Once you've printed the first sheet of
labels, display the field codes by pressing Alt + F9, alter the starting
number in the field code in the top right of the table, press Alt + F9 to
return to viewing the results. Choose Edit, Select All, press F9 and you're
ready to print the next lot of tickets." I tried recording a macro, but have
been stumped after many hours of working on it. To make matters worse, I
don't know macros very well either. I wanted to print the first page,
automatically change the field code in the top right of the table to 4
(increased by 3 each time), print the second page out and so on. I have to
print out 150 tickets.
 
D

Doug Robbins - Word MVP

The best way is to use Mailmerge to labels with an Excel data source.

Or to do it using a macro, on the first ticket on your page, where you want
the numbers to appear, insert the following field

{ DOCVARIABLE varSerialNumber \# "000" }

On the second ticket insert the following field

{ = { DOCVARIABLE varSerialNumber } + 1 \# "000" }

and on the third ticket insert

{ = { DOCVARIABLE varSerialNumber } + 2 \# "000" }

You must use Ctrl+F9 to insert each pair of field delimiters { }. Use
Alt+F9 to toggle of the display of field codes.

Then run a macro containing the following code when that document is active.
It will ask you for the number of tickets that you want to print and then
proceed to print them. If later you want to print some more, just open the
document and run the macro again. It will start numbering tickets from
where the first batch finished.

Dim Message As String, Title As String, Default As String
Dim SerialNumber As Long, NumCopies As Long

' 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.
NumCopies = Val(InputBox(Message, Title, Default))
SerialNumber = Val(System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "SerialNumber"))

If SerialNumber = "0" Then
SerialNumber = 1
End If

ActiveDocument.Variables("varSerialNumber").Value = SerialNumber
Counter = 0

While Counter < NumCopies
With ActiveDocument
.Fields.Update
.PrintOut
.Variables("varSerialNumber").Value =
..Variables("varSerialNumber").Value + 3
End With
Counter = Counter + 3
Wend

'Save the next number back to the Settings.txt file ready for the next use.
System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"SerialNumber") = ActiveDocument.Variables("varSerialNumber").Value

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
C

Craig

Hi Doug,

I get "!Syntax Error, {" on tickets 2 and 3 on both the stub and the ticket.

Also I get a "Compile error: Expected: Expression" on
..Variables("varSerialNumber").Value =
...Variables("varSerialNumber").Value + 3

Craig
 
D

Doug Robbins - Word MVP

The compile error is caused because that command should all be on one line.

For the Syntax error, do you have a space between the 1 and the \ in the 1
\# "000" part of the code, likewise between the 2 and the \ on the third
ticket?


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
C

Craig

Doug,

There are spaces between the 1 and the \ and the 2 and \ on the second and
third tickets.

I had to remove one of the "." on the ".Variables("varSerialNumber").Value =
..Variables("varSerialNumber").Value + 3" line in order for the compile error
to disappear. I also had to add an "End Sub" after
"System.PrivateProfileString("C:\Settings.txt", "MacroSettings",
"SerialNumber") = ActiveDocument.Variables("varSerialNumber").Value" to
eliminate another error.

I'm open to suggestions about the syntax error.

Craig
 
C

Craig

Graham,

Thank you. I have copy of the procedure from your website. It seemed more
complicated to me. I'll see what happens first with Doug Robbin's suggestions.

Craig
 
D

Doug Robbins - Word MVP

It works for me. Perhaps the easiest thing will be for you to send me the
document so I can take a look at it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
C

Craig

Doug,

How do I go about doing that? Your e-mail address on the MVP website is
labelled for paid work only.

Craig
 
D

Doug Robbins - Word MVP

If I invite you to send something to me to look at, I won't be charging you
for it. There is something obvious that you must remove from the email
address that you will see in the newsgroups to be able to send an email
directly to me.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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