PDA

View Full Version : Simple Word form question



erikgutten
06-11-2012, 03:09 PM
I work with creation of simple user imput forms for some templates

I manage to get most of my simple code to work fine, but now i am a bit stuck with these questions, apretiate tips and help very much.

1. Radiobutton

Option Explicit
Dim opttxt1 As String
Private Sub UserForm_Initialize()
If Opt1 = True Then opttxt1 = "editable text" 'to push text in textfield in the form at the same time as radiobutton is selected, when done editing, i push it to document bookmark

End sub


Should i chnge or add to:
Dim opttxt1 as integer, in leu of string function?

2. Checkboxes
Various checkboxes that i plan on to insert text from a wide range of docs,
place them in the "master doc", but without knowing how to get the text to be placed where i want, without loosin next bookmark..
Example:

Dim oRng As Word.Range
Dim oBM As Bookmarks
Set oBM = ActiveDocument.Bookmarks
Set oRng = oBM("sometitle").Range
oRng.Text = chk1.result' goto folder get text from doc, insert text


For as many as 50 or more predefined docs, in one specific folder, all with unike filenames (i controle that)

My purpose of this is to make it so that rather i do the job that i mean other can do, for documenting sold products, etc. -also for tendering bids...

any ideas?

Tinbendr
06-12-2012, 03:43 AM
Welcome to the board!

First off, the radiobutton code you have will never be true since all buttons/checkboxes are not set when a userform starts. (initializes).

So, more about optionbuttons. Put groups of opts in a frame. Then they become mutually exclusive. (Only one in the group can be selected.)

To set one button.
optButton1.Value = True
If OptButton1 = True Then
TextBox1.Value = "'Option Number 1"
End if
Controls usually have values, Captions, or text.
MyControl.Value
MyControl.Caption
MyControl.Text

They are all listed in the properties panel when you have a particular control selected.

Checkboxes are mutually inclusive. (You can select as many as you want.) and they are set the same way.

To check the values of the optionbuttons, use a select case statement.

Select Case True
Case optionButton1
'Do something

Case OptionButton2
'Do more

End Select See this link (http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm) on using bookmarks without destroying them.

It's hard to suggest options when you haven't provided a sample, but I collect all the info in the userform, then with a commandbutton, push all the data to the document.

gmaxey
06-12-2012, 04:33 AM
David,

Option buttons don't have to be in a frame to be mutually exclusive. Just give them the same groupname property.

Frosty
06-12-2012, 09:44 AM
Bravo Greg... you have once again pointed out something I had no idea about. Thank you!

gmaxey
06-12-2012, 05:37 PM
Jason,

I'm like the blind squirrel that sometimes finds a nut.

Frosty
06-12-2012, 07:35 PM
Well, at the risk of ruining the metaphor...

You've got a lot of nuts ;)

gmaxey
06-13-2012, 05:14 AM
Jason,

That is a feather I'll put in my cap. Thanks.