Word 2000 Macro Help

R

Ryan

Hello,

I am making a form with macros for my job. The user fills in name,
phone number, manager, and department, then chooses from a list of
pager groups. Once all this is done, the user hits the submit button
and a copy of the form is emailed to me.

Everything works fine except the copy of the form I get contains a
blank listbox (which is where the checkboxes for the groups are
located)

The code is as follows:

'array for storing listbox options
Dim lb1(0 To 23) As String
Dim lb2(0 To 23) As String
'Counters for each array to step through the elements
Dim lb1count As Integer
Dim lb2count As Integer
Private Sub Document_New()


'Define elements of the array
lb1(0) = "First Responders"
lb1(1) = "AAA TEMP EAP"
lb1(2) = "Allied Services"
lb1(3) = "Automation"
lb1(4) = "BOLT"
lb1(5) = "COD DAILY"
lb1(6) = "Contractors"
lb1(7) = "Food Safety"
lb1(8) = "FSSC"
lb1(9) = "Kronos Approval"
lb1(10) = "Leadership Group"
lb1(11) = "MCM Group"
lb1(12) = "MIT Members"
lb1(13) = "MWL All"
lb1(14) = "MWL Leadership Team"
lb1(15) = "PGLA Managers"
lb1(16) = "Sensory Testers"
lb1(17) = "Waste Water"
lb1(18) = "Emergency Communications"
lb1(19) = "Process Grind"
lb1(20) = "24 Hr. Instrumentation"
lb1(21) = "MWL Automation"
lb1(22) = "PGLA Automation"

lb2(0) = "First Responders"
lb2(1) = "AAA TEMP EAP"
lb2(2) = "Allied Services"
lb2(3) = "Automation"
lb2(4) = "BOLT"
lb2(5) = "COD DAILY"
lb2(6) = "Contractors"
lb2(7) = "Food Safety"
lb2(8) = "FSSC"
lb2(9) = "Kronos Approval"
lb2(10) = "Leadership Group"
lb2(11) = "MCM Group"
lb2(12) = "MIT Members"
lb2(13) = "MWL All"
lb2(14) = "MWL Leadership Team"
lb2(15) = "PGLA Managers"
lb2(16) = "Sensory Testers"
lb2(17) = "Waste Water"
lb2(18) = "Emergency Communications"
lb2(19) = "Process Grind"
lb2(20) = "24 Hr. Instrumentation"
lb2(21) = "MWL Automation"
lb2(22) = "PGLA Automation"
'Zero out the counters
lb1count = 0
lb2count = 0
'Populate the listboxes
Do
ListBox1.AddItem (lb1(lb1count))
lb1count = lb1count + 1
Loop Until lb1count >= 23

Do
ListBox2.AddItem (lb2(lb2count))
lb2count = lb2count + 1
Loop Until lb2count >= 23

End Sub
Private Sub ListBox1_Click()


End Sub

Private Sub ListBox2_Click()

End Sub

Private Sub cmdEmail_Click()

'Disable button so multiple emails aren't sent
cmdEmail.Enabled = False
'Change Caption so user knows whats going on
cmdEmail.Caption = "Submitting"
'Set up email properties
ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
..Subject = "Pager Service Request"
..AddRecipient "(e-mail address removed)"
'Groups selected are added to body of email...
..Message = "ThisWillChange"
..Delivery = wdAllAtOnce
End With

'Send email
Options.SendMailAttach = True
ActiveDocument.Route
End Sub

Any help is appreciated!
 
C

Cindy M.

Hi Ryan,
I am making a form with macros for my job. The user fills in name,
phone number, manager, and department, then chooses from a list of
pager groups. Once all this is done, the user hits the submit button
and a copy of the form is emailed to me.

Everything works fine except the copy of the form I get contains a
blank listbox (which is where the checkboxes for the groups are
located)
Did you use the Control Toolbox for the fields on this form? Such
lists are automatically emptied as soon as the document is closed.
You'll need code to persist the settings, and recreate them if that's
what you want. (Although if you're interested only in the data you
could access, say document Variables or Properties without having to
rebuild the lists.)
The code is as follows:

'array for storing listbox options
Dim lb1(0 To 23) As String
Dim lb2(0 To 23) As String
'Counters for each array to step through the elements
Dim lb1count As Integer
Dim lb2count As Integer
Private Sub Document_New()


'Define elements of the array
lb1(0) = "First Responders"
lb1(1) = "AAA TEMP EAP"
lb1(2) = "Allied Services"
lb1(3) = "Automation"
lb1(4) = "BOLT"
lb1(5) = "COD DAILY"
lb1(6) = "Contractors"
lb1(7) = "Food Safety"
lb1(8) = "FSSC"
lb1(9) = "Kronos Approval"
lb1(10) = "Leadership Group"
lb1(11) = "MCM Group"
lb1(12) = "MIT Members"
lb1(13) = "MWL All"
lb1(14) = "MWL Leadership Team"
lb1(15) = "PGLA Managers"
lb1(16) = "Sensory Testers"
lb1(17) = "Waste Water"
lb1(18) = "Emergency Communications"
lb1(19) = "Process Grind"
lb1(20) = "24 Hr. Instrumentation"
lb1(21) = "MWL Automation"
lb1(22) = "PGLA Automation"

lb2(0) = "First Responders"
lb2(1) = "AAA TEMP EAP"
lb2(2) = "Allied Services"
lb2(3) = "Automation"
lb2(4) = "BOLT"
lb2(5) = "COD DAILY"
lb2(6) = "Contractors"
lb2(7) = "Food Safety"
lb2(8) = "FSSC"
lb2(9) = "Kronos Approval"
lb2(10) = "Leadership Group"
lb2(11) = "MCM Group"
lb2(12) = "MIT Members"
lb2(13) = "MWL All"
lb2(14) = "MWL Leadership Team"
lb2(15) = "PGLA Managers"
lb2(16) = "Sensory Testers"
lb2(17) = "Waste Water"
lb2(18) = "Emergency Communications"
lb2(19) = "Process Grind"
lb2(20) = "24 Hr. Instrumentation"
lb2(21) = "MWL Automation"
lb2(22) = "PGLA Automation"
'Zero out the counters
lb1count = 0
lb2count = 0
'Populate the listboxes
Do
ListBox1.AddItem (lb1(lb1count))
lb1count = lb1count + 1
Loop Until lb1count >= 23

Do
ListBox2.AddItem (lb2(lb2count))
lb2count = lb2count + 1
Loop Until lb2count >= 23

End Sub
Private Sub ListBox1_Click()


End Sub

Private Sub ListBox2_Click()

End Sub

Private Sub cmdEmail_Click()

'Disable button so multiple emails aren't sent
cmdEmail.Enabled = False
'Change Caption so user knows whats going on
cmdEmail.Caption = "Submitting"
'Set up email properties
ActiveDocument.HasRoutingSlip = True
With ActiveDocument.RoutingSlip
..Subject = "Pager Service Request"
..AddRecipient "(e-mail address removed)"
'Groups selected are added to body of email...
..Message = "ThisWillChange"
..Delivery = wdAllAtOnce
End With

'Send email
Options.SendMailAttach = True
ActiveDocument.Route
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
Top