Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

fill in text fields

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bart - 09 Jan 2005 11:28 GMT
Hello,

I have a document with a form, which has a few text-fields on it. The
document is protected from changes, except the text-fields.

I made a dialog in VBA where you can select certain data that should be
filled in in the selected text-field. I thought I could do this with:

   Selection.TypeText Text:="filled data"

But I get error 4605 , stating this method or property is not available
because the document is locked from changes.

My question is: how can I get a text in the selected textfield from VBA?

Any help will be appreciated.

  Greetings!
Greg Maxey - 09 Jan 2005 12:02 GMT
Bart,

I don't follow exactly what you are trying to do, but if you need to access
a protected form to do something you can use:

ActiveDocument.Unprotect
...Do something
Active Document.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> Hello,
>
[quoted text clipped - 16 lines]
>
>   Greetings!
Bart - 09 Jan 2005 14:00 GMT
The document is protected, except for the fields.

I need to fill in the field that is currently selected.

How can I do that?

> Bart,
>
[quoted text clipped - 4 lines]
> ...Do something
> Active Document.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
Jay Freedman - 09 Jan 2005 14:04 GMT
Hi Bart,

If the length of the data from the dialog is less than 256 characters,
you can fill the formfield with it without unprotecting the form. It
takes some convoluted syntax, though:

 Selection.Bookmarks(1).Range.Fields(1).Result.Text = "filled data"

If the string is 256 characters or more, you'll have to unprotect and
reprotect -- see
http://word.mvps.org/FAQs/MacrosVBA/SetLongFmFldResult.htm.

There's absolutely no way to use Selection.TypeText to do this. The
Selection includes not just the "fillable" portion of the formfield,
but also the formfield itself (represented by the braces when you
display field codes). When you try to use TypeText, VBA thinks you're
trying to replace the whole field with plain text, which isn't allowed
when the form is protected.

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Bart,
>
[quoted text clipped - 25 lines]
>>
>>   Greetings!
Bart - 09 Jan 2005 15:18 GMT
thx

do you know how i can move to the next field after performing this command?

"Jay Freedman" <jay.freedman@verizon.net> wrote in message
> Hi Bart,
>
[quoted text clipped - 19 lines]
> Jay Freedman
> Microsoft Word MVP         FAQ: http://word.mvps.org
Greg Maxey - 09 Jan 2005 16:06 GMT
Bart,

I still don't understand precisely what it is that you are trying to do, but
if you are trying to put some text using VBA in a selected formfield and
then move immediately to the next field then I suppose that you could use
something like this:

Dim oFld
Dim oFormFld As String
Set oFld = ActiveDocument.FormFields

Selection.Bookmarks(1).Range.Fields(1).Result.Text = "Filled Data"
oFormFld = Selection.Bookmarks(1).Name
 If oFld(oFormFld).Name <> oFld(oFld.Count).Name Then
   oFld(oFormFld).Next.Select
 Else
   oFld(1).Select
 End If

This means of course that you are not going to get a chance to edit the
Filled Data

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> thx
>
[quoted text clipped - 25 lines]
>> Jay Freedman
>> Microsoft Word MVP         FAQ: http://word.mvps.org
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.