PDA

View Full Version : Solved: Dropdown FormField Inserting Files



petedw
04-28-2005, 03:54 AM
Hi, hope you can help! Im a bit new to this

I have created a form on word using Dropdown and Text Formfields. I have the following macro running on exit in a Dropdown Formfield (Dropdown1). How can i get it to insert the text from the file in a Text Formfield (Text1) instead of at the end of the document??


Sub DropSelection()
Dim myrange As Range
ActiveDocument.Unprotect
Set myrange = ActiveDocument.Range
myrange.Collapse wdCollapseEnd
myrange.InsertFile "C:\Documents and Settings\pwilliams\My Documents\" & _
ActiveDocument.FormFields("DropDown1").DropDown.Value & ".doc"
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset
End Sub


Many Thanks
Pete

TButhe
04-28-2005, 07:51 AM
Hi,

Check out this thread, if I am understanding you correctly this may help. http://www.vbaexpress.com/forum/showthread.php?t=1996

If this isn't what you need just post back I KNOW someone here can help. They always manage to sort out my messes!!

Have a great day!! Tracy

petedw
04-28-2005, 08:13 AM
This only seems to tell me how to insert text from within the same document.

I need to know how to insert text from another word document into my current word document. I need this text to drop into a text formfield. Also i need it to be activated by a Dropdown formfield.

I hope someone can help!

newk
04-28-2005, 08:19 AM
Hi Pete,

How are you fairing up? It's a nightmare when you get stuck!

Please could you attach an copy of your document and I'll try and help.

Kieran

Killian
04-28-2005, 08:28 AM
Hi Pete,

You use the "InsertFile" method with "myrange". Previously, you set myrange to the end of the documentSet myrange = ActiveDocument.Range
myrange.Collapse wdCollapseEndso what you need to do instead is set myrange to the range of your target instead (the text formfield)'where "Text1" is the name of your text form field
Set myRange = ActiveDocument.FormFields("Text1").Range
myRange.InsertFile "C:\Documents... etc, etc..."

MOS MASTER
04-28-2005, 10:50 AM
Hi Pete,
so what you need to do instead is set myrange to the range of your target instead (the text formfield)'where "Text1" is the name of your text form field
Set myRange = ActiveDocument.FormFields("Text1").Range
myRange.InsertFile "C:\Documents... etc, etc..."

Hi K, :D

This code will overwrite the range of the formfield so the field is no longer available for editing! (It's in the protected section of the document now as plain text)

Perhaps this is what Pete's after but it seams to me he want the contents off that file in the formfield so he can edit it some more.

So Pete can you clarify what you want? :rofl:

petedw
04-29-2005, 12:54 AM
MOS MASTER,

You are correct, i do need the contents of the file to appear in the formfield (as apposed to overwriting the formfield).

Hope you can come up with a solution to this.

Many Thanks

Pete

Killian
04-29-2005, 01:55 AM
Good call Joost!
If the field is still required afterwards then you need to return a range object from inside the text field to apply the insert file method. The simplest (and admittedly least elegant) way of doing that is to move the selection object in thereActiveDocument.FormFields("Text1").Select
Selection.MoveLeft wdCharacter, 1
Selection.MoveRight wdCharacter, 1
Selection.InsertFile "C:\ etc, etc..."

petedw
04-29-2005, 07:25 AM
Thanks Killian,

That worked fine for me.

Also, i would like to run a macro on entry to a dropdown formfield that left clicks on the dropdown menu for me.

I know that the syntax is: FieldObject.DoClick

I hope you can help me on this.

Thanks again
Pete

Killian
04-29-2005, 07:54 AM
np Pete,

You can either set the exit macro when you create the dropdown or with VBAActiveDocument.FormFields("Dropdown1").ExitMacro = "Macro1"

petedw
04-29-2005, 08:51 AM
That doesn't answer my question. I have a Dropdown Formfield (Dropdown1) and i require a Macro that i can set to Run On Entry.

The macro i require needs to left click on the Dropdown Formfield for me?
Do you get what i mean? It's quite hard to explain

Pete

Killian
04-29-2005, 09:02 AM
As far as I'm aware. you can have a marco run when you enter the dropdown and when you exit.
these are set with the "EntryMacro" and "ExitMacro" properties of the specified formfield object.
I've noticed that the Entry marco fires when you arrow key or tab down to the dropdown, but doesn't when you select it directly by left-clicking. It seems to skip the "enrty" part and go straight to dropping down (for which there is no event).
This is the kind of flakey behaviour I've come to expect from Word. Is that a problem?

MOS MASTER
04-29-2005, 11:16 AM
Hi Killian, :D

Thanx!

You're right there is now dropdown property to show the list om a formfield dropdown.

@pete,

However you can simulate the keystrokes with the Sendkeys method.

This works for me in a entry macro:
Sub DropDownList()
SendKeys "%{DOWN}", True
End Sub


It presses ALT+Arrow down to open the list!

Enjoy! :whistle:

petedw
04-29-2005, 02:07 PM
You guy's are great!:yes

Thank you, thank you, thank you!!!!!

Pete

MOS MASTER
04-29-2005, 02:09 PM
You're Welcome! :beerchug:

MOS MASTER
04-30-2005, 11:40 AM
You guy's are great!:yes

Thank you, thank you, thank you!!!!!

Pete
Hi Pete, :D

Almost forgotten...could you mark you're thread solved? :whistle: