userforms

L

LizPCS

Hello,
Even though I am a beginner, my boss seems to think I am capable o
advanced programming. I am trying to create some macros/forms in Wor
that were originally in WP for one of our clients. I have already don
a lot of research and am well aware that there is no way to conver
pretty much anything from WP to Word so I am starting from basicall
scratch. I am not here to complain about Word, just need help tryin
to create this form (this is the easiest one, so you will probably b
hearing a lot more from me). Ok so I've got a template with bookmark
and I am trying to create a dialog box (userform, I think) which i
associated with the bookmarks. The dialog box has some text boxes bu
it also has radio buttons, and list boxes and text boxes in case the
dont want whats in the list box, and check boxes with text boxes tha
enter the text if the check box is checked...ok you get the point.
So the document which directed me to this poin
(http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm) only explain
how to use text boxes and then a command button that holds all the cod
(I think)...

How do I associate each radio button/list box/checkbox/text box ec
with the correct bookmark and at the same time I would like to us
if/then...I think...like if they select ABC in the list box then a
this bookmark it says "ABC company" (return) "Philadelphia, PA
(return) "(e-mail address removed)"

Sorry if this is a complete waste of time...I should probably just ge
a VBA for dummies book...but I think I'm catching on...

Any help is greatly appreciated.
Thanks.
Li
 
L

LizPCS

Ok so do I just put all the if/then statements on the OK
button?........my brain hurts...
Liz
 
K

Kerry

Hi Liz

I understand your dilemna. I have been learning how to make these forms myself over the last few weeks and I must say I am pretty pleased with my progress. I got all my help from the Woodys Lounge forum. http://www.wopr.com/

I can highly recommend you go there and take a look at the last couple of weeks posts for Word. You will see what I have learnt.

I wish I had more time to help you along but I think you will find what you need at Woodys.

Good luck
Kerryg
 
M

Mark Tangard

Liz,

The brainpain is normal.

Yes, often the bulk of your code does go in the OK button, in its _Click
event. But it all depends on what your form does. For example, if
you're validating entries as the user makes them, some code will go in
the _Exit event of, say, each TextBox control, so you can scold and
redirect the user as he stumbles, rather than later. It can't hurt to
start out with most of your code in the OK_Click event (that assumes
your OK button control is named OK). You can refine the structure
later, after the nightmares. ooh, just kidding. sort of.

It may help to see a form that works and is a little more complicated
than the one in the tutorial. You can download one at
http://www.speakeasy.org/~mtangard/userform_sample.html. It's
imperfect, but at this point you're probably aiming for a better grasp
of basic concepts rather than nuances.

Hope this helps a bit. Keep posting.
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Liz,

Maybe this will be another piece of the puzzle. I am in the process of
preparing a revision and an expansion of the article at
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm to cover the use of
things such as comboboxes, list boxes, radio buttons etc. etc. but there are
some many things that you can do with a userform, that I am finding it
difficult to cover the subject as much as I would like, while keeping it
reasonably concise.

This routine loads a listbox with client details stored in a table in a
separate
document (which makes it easy to maintain with additions, deletions etc.),
that document being saved as Clients.Doc for the following code.

On the UserForm, have a list box (ListBox1) and a Command Button
(CommandButton1) and use the following code in the UserForm_Initialize() and
the CommandButton1_Click() routines

Private Sub UserForm_Initialize()
Dim sourcedoc As Document, i As Integer, j As Integer, myitem As Range,
m As Long, n As Long
' Modify the path in the following line so that it matches where you
saved Suppliers.doc
Application.ScreenUpdating = False
' Open the file containing the client details
Set sourcedoc = Documents.Open(FileName:="e:\worddocs\Clients.doc")
' Get the number or clients = number of rows in the table of client
details less one
i = sourcedoc.Tables(1).Rows.Count - 1
' Get the number of columns in the table of client details
j = sourcedoc.Tables(1).Columns.Count
' Set the number of columns in the Listbox to match
' the number of columns in the table of client details
ListBox1.ColumnCount = j
' Define an array to be loaded with the client data
Dim MyArray() As Variant
'Load client data into MyArray
ReDim MyArray(i, j)
For n = 0 To j - 1
For m = 0 To i - 1
Set myitem = sourcedoc.Tables(1).Cell(m + 2, n + 1).Range
myitem.End = myitem.End - 1
MyArray(m, n) = myitem.Text
Next m
Next n
' Load data into ListBox1
ListBox1.List() = MyArray
' Close the file containing the client details
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub

Private Sub CommandButton1_Click()
Dim i As Integer, Addressee As String
Addressee = ""
For i = 1 To ListBox1.ColumnCount
ListBox1.BoundColumn = i
Addressee = Addressee & ListBox1.Value & vbCr
Next i
ActiveDocument.Bookmarks("Addressee").Range.InsertAfter Addressee
UserForm2.Hide
End Sub

The Initialize statement will populate the listbox with the data from the
table and then when a client is selected in from the list and the command
button is clicked, the information for that client will be inserted into a
bookmark in the document. You may want to vary the manner in which it is
inserted to suit our exact requirements, but hopefully this will get you
started.

To make it easy for you, the code has been written so that it will deal with
any number of clients and any number of details about each client. It
assumes that the first row of the table containing the client details is a
header row.


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
L

LizPCS

Thanks everyone for all your help. We actually have called in someon
who has programming experience to help us with this project. She and
are working together and have made some progress. Doug, we were jus
discussing using data from a spreadsheet to load the listbox, so you
reply will be most helpful. Thanks again to everyone and you may b
hearing from us soon.
Li
 

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