|
-
Jun 17th, 2005, 06:34 AM
#1
How do I dynamically create textboxes in a custom word form - Resolved
I have a customer form fired up from a word macro and I want to create a number of textboxes on it. I have to create them dynamically as I don't know how many at design time.
My own investigations and a trawl round the forums pointed me at 2 possible ways of achieving it but neither's working for me:-
1 txtBox = Me.Controls.Add(progid, "txtField", True) The problem here is I can't work out the progid for a text box - various sources quote VB.TextBox but word doesn't seem to recognise VB - maybe I just need to add a reference but I can't work out which.
2 Create an control array with a single element and then 'load' it to create new instances of the control in the array, something like: Load txtField(1) The problem with this one is that word doesn't seem to support control arrays - the text box has no index property and if I try to add an identically named control it barfs and tells me the name's ambiguous, no option to create an array.
So can anyone tell me how to:-
get the progID in word for a text box
or
create a control array in word
or
do something else entirely?
Thanks in advance
Last edited by FunkyDexter; Jun 22nd, 2005 at 04:01 AM.
-
Jun 17th, 2005, 07:34 AM
#2
Re: How do I dynamically create textboxes in a custom word form
are you refering to a textbox as in a document frame or a text form field?
if the latter,
Add Method (FormFields Collection) Example
This example adds a check box at the end of the selection, gives it a name, and then selects it.
Selection.Collapse Direction:=wdCollapseEnd
Set ffield = ActiveDocument.FormFields _
.Add(Range:=Selection.Range, Type:=wdFieldFormCheckBox)
With ffield
.Name = "Check_Box_1"
.CheckBox.Value = True
End With
from help
pete
-
Jun 17th, 2005, 08:00 AM
#3
Re: How do I dynamically create textboxes in a custom word form
I'm not even sure what that meant. eeep!
I think what that would do is put a textbox on my word document? If so it's not what I'm after I'm afraid.
What I'm looking for is the equivalent of a text box on a normal vb form. In words vb editor insert a userform into your project and open up the toolbox. There's a textbox control (third control from left but that might be dynamic for all I know - it's called textbox) that you can drag onto your form and it'll create a textbox. That's what I want but I want to create it from code.
-
Jun 17th, 2005, 08:03 AM
#4
Frenzied Member
Re: How do I dynamically create textboxes in a custom word form
Tengo mas preguntas que contestas
-
Jun 17th, 2005, 08:12 AM
#5
Re: How do I dynamically create textboxes in a custom word form
yes the code i posted puts a vb style textbox for a word form
but if in word you goto menu> insert> textbox that is completely different
pete
-
Jun 17th, 2005, 08:32 AM
#6
Re: How do I dynamically create textboxes in a custom word form
@westconn1, Yeah, that's not what I'm looking for I'm afraid - both are examples of putting 'textboxes' onto the word document itself whereas I want to put one onto a custom userform. The input wasn't wasted though as I think I'm going to want to do that soon anyway so thanks.
@salvelinus, Yeah, I'd seen that thread but it actually didn't help much. In your post in that thread you declare the textbox but never instantiate it - I get a 'object not set' error if I do that. There's a link off the thread that shows you how to do the Load thing on a control array but that won't work because I can't create a control array. Finally, Silvrwood ends up putting a load of invisible textboxes on the form and dynamically making them visible - this is what I'm doing at the moment as a workaround but it's cludgy and I don't like it - surely you MUST be able to create them dynamically, you can in standard VB.
-
Jun 17th, 2005, 09:08 AM
#7
Re: How do I dynamically create textboxes in a custom word form
here is how to dynamically create text boxes on a userform
VB Code:
Dim Mytb As Control
Private Sub CommandButton1_Click()
Set Mytb = Controls.Add(("Forms.textbox.1"), "textbox2", Visible)
Mytb.Left = 18
Mytb.Top = 100
Mytb.Width = 175
Mytb.Height = 20
Mytb.Text = "This is fun." & Mytb.Name
End Sub
this is tested and working
textbox2 is the name of the created textbox, change as required
if you want to create a heap of them you can do it in a for next loop
pete
Last edited by westconn1; Jun 17th, 2005 at 09:15 AM.
-
Jun 17th, 2005, 09:24 AM
#8
Re: How do I dynamically create textboxes in a custom word form
Now that looks like what I'm after. BIG thanks
I've tried it in my form and it runs with no errors but the textboxes don't actually appear. I've made sure visible is true and that the top and left properties would leave it in a visible part of the form . It has a height and width. I can't think of any other reason it wouldn't show up. Any thoughts?
-
Jun 17th, 2005, 10:13 AM
#9
Re: How do I dynamically create textboxes in a custom word form
it showed in my form ok when i was trying it, makes sure it isn't under the command button or something else
pete
-
Jun 17th, 2005, 10:24 AM
#10
Re: How do I dynamically create textboxes in a custom word form
Actually, I've got a couple of frames on the form and it should appear in one of them. I wonder if it's hiding behind one of them. Anyway, I doubt I'll get time to experiment with it further today so I'll have another crack at after the weekend.
Thanks for all your help, Westy
-
Jun 17th, 2005, 10:38 AM
#11
Re: How do I dynamically create textboxes in a custom word form
to put the textbox onto the frame you will have set its container
if that exists in vba
pete
-
Jun 17th, 2005, 10:51 AM
#12
Re: How do I dynamically create textboxes in a custom word form
turns out to be easy
Set Mytb = Frame1.Controls.Add(("Forms.textbox.1"), "textbox" & i, Visible)
remember that top is now measured in the frame
pete
-
Jun 17th, 2005, 11:00 AM
#13
Re: How do I dynamically create textboxes in a custom word form
By the way, where did you find that ("Forms.textbox.1") value? I think it's basically the progID I was looking for in my first post isn't it?. I'm going to need to add other controls later and I could do with a reference.
-
Jun 17th, 2005, 11:04 AM
#14
Re: How do I dynamically create textboxes in a custom word form
i found it in the vba help file
pete
-
Jun 17th, 2005, 12:33 PM
#15
Re: How do I dynamically create textboxes in a custom word form
aha, found it. The machine I was working on today didn't have the help files installed so I was searching the net.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|