PDA

View Full Version : Show Form Query & Radio Buttons



Greg
10-08-2006, 07:45 AM
Hi all,

Some time ago MD provided me with a document and code that I have struggled with ever since. That document is attached.

My problem is this: How do I get control over the "show form" button that appears when I run the macro on that documet? Everything else in the document is fairly obvious but I can't see any code, etc that relates to the said button.

If I could contol the location, size and name of the button it may be a useful addition to some of my documents.

A second question relates to the use of radio buttons. I have some Word documents with radio buttons, which when selected, call up autotext entries for insertion into specific bookmarks.

Whilst these are useful to me, they become problematic if other users want to use the documents because we all use different "normal" templates and of course the autotext is not present in those other templates.

I would prefer that the document and its associated macros were accessable by all without having to worry about the autotext as well. Is there a simple solution to this?

I hope you can help.

Greg.

Norie
10-08-2006, 08:29 AM
Greg

Exactly what control do you want/need for the button?

The only code associated with it is this, which is located in the ThisDocument module.


Public Sub CommandButton1_Click()
UserForm2.Show
End Sub

mdmackillop
10-08-2006, 11:42 AM
Hi Greg,
By using Tools/Templates/Organiser, you can copy macros, autotext etc. from Normal into your project template.

fumei
10-08-2006, 06:27 PM
First, As has been stated, put your autotext entries into their own template. That way they can used by anyone using the template.

Second, the use of the code: Selection.GoTo What:=wdGoToBookmark, Name:="MyText"
Selection.TypeText Text:=TextBox1 is not the best way to do this. You may notice that if you use it a second time the text is appended to the previous text. This MAY be what you want, but I suspect that it probably is not.

There is a way to have a procedure always replace the bookmark text. In fact, as it stand right now, if you use your userform and insert tect, then go to the document and go to that bookmark...the text you inserted will NOT be selected. Your code does NOT make the bookmark text the inserted text.Sub FillABookmark(strBM_Name As String, strBM_Text As String)
On Error Resume Next
With Selection
.GoTo what:=wdGoToBookmark, Name:=strBM_Name
.Collapse Direction:=wdCollapseEnd
ActiveDocument.Bookmarks(strBM_Name).Range.Text = strBM_Text
.MoveEnd unit:=wdCharacter, Count:=Len(strBM_Text)
ActiveDocument.Bookmarks.Add _
Name:=strBM_Name, Range:=Selection.Range
.Collapse Direction:=wdCollapseEnd
End With
End Subwill always replace the actual bookmark text. So instead of:Public Sub CommandButton1_Click()
Selection.GoTo What:=wdGoToBookmark, Name:="MyText"
Selection.TypeText Text:=TextBox1
End Subyou can use:Public Sub CommandButton1_Click()
Call FillABookmark("MyText", TextBox1)
End SubNot only does this allow clean replacement of the bookmark text, but it allows as many changes to that text as you like.

Greg
10-14-2006, 11:41 PM
Thanks fumei, that's bloody brilliant. I'll always do that from now on.

However, I still have one small problem. When I open that document, the "Show form" button is positioned on the page of the document itself.

My query in that regard is this - How do I control the location of that button (I may wish to situate it elsewhere on the page) and how can I change it to say something else? I expect that the answer is simple but it has evaded me so far.

Greg.

mdmackillop
10-15-2006, 12:59 AM
I've always found these buttons a bit unfriendly as well, but that may be because I don't understand how to use them properly. As a workaround, you could cut and paste it into as textbox, which you can drag about on the page.
You can, of course, replace the page button with a toolbar button, shortcut, or anything else that has a Click event.
Regards
MD

fumei
10-15-2006, 06:51 AM
The properties of an ActiveX control - which is what that is - can be accessed by right clicking the control when you are in Design Mode. You get the Design Mode toggle from the Control Toolbox toolbar. You can also do this directly in the VBE.

You must know how to change what it says. The default Caption is not "Show Form". Did someone else do this. In any case, what the button displays as text is the Caption property.

As for placement on the page....sigh....by default when you insert an ActiveX control it is placed as an InlineShape. That means it is...in line. You can not place it anywhere you want. It is...in line.

Now, here is where Word gets very strange.

YES - you can copy and paste the ActiveX control into a textbox. Bit....wait for it. It is NOT a real copy. It is a new control. The control "pasted" will NOT have the code. This is important. Doing a "paste" will append a "1" after the name of the control that was "copied". It is a NEW control.

More weirdness...while you can "copy" and "paste" an ActiveX control into a textbox...you can NOT Insert one!

MORE weirdness...if you "copy" and "paste" the ActiveX control into textbox, the textbox takes priority as a Shape (not an InlineShape) and the ActiveX control is NOT considered a real "object". If you do a .Count of both InlineShapes and Shapes you would get 1 Shape (0 InlineShapes)...for the textbox.

Even MORE weirdness...OK, now you have the ActiveX control in a textbox. Move it out of the frame. You can move it where ever you like. Now....delete the frame! You can still move the control where ever you like.

fumei
10-15-2006, 06:58 AM
Some final points. Using ActiveX controls can certainly be useful, especially commandbuttons. The main reason is that they have events. However, as Malcolm points out there are many other ways to fire a procedure. An icon on a toolbar, a menu item, a keyboard shortcut.

Further, if the procedure that is to be fired by the commandbutton is one that you want to do automatically, then IMHO it is better to use one of the automatic, built-in procedures, such as Document_Open to do whatever.

As last comments, I would recommend:

1. You use Option Explicit for ALL files that are going to run code.

2. Explicitly name ALL controls. Do not use the default names, such as "Commandbutton1".

3. Try to get into the habit of having Show/Hide set to ON. I know most people hate seeing all those pilcrows (the paragraph marks), but actually, seeing those marks is a GOOD thing when seriously working with Word.

mdmackillop
10-15-2006, 07:46 AM
Try to get into the habit of having Show/Hide set to ON. I know most people hate seeing all those pilcrows (the paragraph marks), but actually, seeing those marks is a GOOD thing when seriously working with Word.
Of course the reason most people turn this off is because they have so many pilcrows and tab marks cluttering up the page. With a properly Styled document, you'll only have one pilcrow per paragraph, the occasional extra tab, and maybe a linebreak or two. :whistle:

Thanks for the additional info on ActiveX, Gerry. Very useful.

fumei
10-17-2006, 01:17 AM
Yes, that is exactly the reason people don't like Show/Hide on. It shows all the crap they do not need, and should not be using. Precisely, a proper use of Styles does indeed have one paragraph mark per paragraph....of course even if you don't use Stles properly, there is still only one paragraph mark per paragraph...

The "cluttering up" of paragraph marks usually indicates that you have used the Enter key (which makes a new pargraph) to make the space between paragraphs with text. Of course if you use Styles you NEVER have to do this.

Greg
12-07-2006, 01:53 AM
Hi Gerry,

I hope you get this. It's been a long time.

My question is simply this: How do you ensure that the ActiveX button doesn't appear on the printed document?

I had it working nicely at one stage but somehow spoiled and now I can't remember what changes I made.

Can you help?

Greg.

Greg
12-07-2006, 05:52 AM
Tools/options/print and untick drawing objects?

Is there some easy code for this?