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 / November 2005

Tip: Looking for answers? Try searching our database.

For, code for button to save and clear form  fields

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
skateblade - 10 Nov 2005 13:52 GMT
As a volunteer for a drug rehab centre,  I have created a form in Word with
lots of drop downs form fields, text boxes and tables with text boxes inside
them. This form will be used by lots of field consultants in there offices
and in the field on laptops. They will fill in the form in the field and save
the file then print it when they return to there office.

I would like to add a button to the form that will "save the file taking the
file to save to from the text box with the clients name in it and then clear
the form" so they can start another client, without reloading the form from
the template. I guess if this can’t be done then have the button save the
file then reload the template form.
Anybody have any ideas.
Thanks Malcolm
Edward Thrashcort - 10 Nov 2005 14:39 GMT
Add two macros to the document, called "FileSave" and "FileSaveAs" and use
VBA to extract the text from the source field and patch it into the
Save/Save-as dialog.

By naming the macros thus, you replace Words native commands for that
document.

Eddie
skateblade - 10 Nov 2005 15:11 GMT
Thanks for the response,
That sounds great but how do I do that.
I have a limited knowledge of how to do code.
Thanks for your help.
Malcolm

> Add two macros to the document, called "FileSave" and "FileSaveAs" and use
> VBA to extract the text from the source field and patch it into the
[quoted text clipped - 4 lines]
>
> Eddie
Doug Robbins - Word MVP - 10 Nov 2005 19:26 GMT
Dim i As Long
With ActiveDocument
   .SaveAs "[Drive:\Folder\]" & .FormFields("ClientName").result
   For i = 1 To .FormFields.Count
       .FormFields(i).result = ""
   Next i
End With

You will need to replace the square brackets and the content within them
with the actual drive and folder path where you want the documents stored.

c:\formdata\

for example

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Thanks for the response,
> That sounds great but how do I do that.
[quoted text clipped - 11 lines]
>>
>> Eddie
skateblade - 10 Nov 2005 20:05 GMT
Thanks a lot it looks great, I will try it.

Malcolm

> Dim i As Long
> With ActiveDocument
[quoted text clipped - 26 lines]
> >>
> >> Eddie
skateblade - 11 Nov 2005 14:28 GMT
I tried it, couldn't get it to work. Must be doing something wrong.
This is the code I put in:

Private Sub CommandButton1_Click()
With ActiveDocument
 .SaveAs "[C:\Documents and Settings\HP_Owner\My Documents\Word]" &
.FormFields("ClientName").Result
   For i = 1 To .FormFields.Count
       .FormFields(i).Result = ""
   Next i
End With
End Sub

Thanks
Malcolm

> Thanks a lot it looks great, I will try it.
>
[quoted text clipped - 30 lines]
> > >>
> > >> Eddie
Jonathan West - 11 Nov 2005 15:00 GMT
Doug mentioned that you don't want the square brackets in the pathname.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

>I tried it, couldn't get it to work. Must be doing something wrong.
> This is the code I put in:
[quoted text clipped - 50 lines]
>> > >>
>> > >> Eddie
Doug Robbins - Word MVP - 11 Nov 2005 16:12 GMT
Remove the square brackets [ ].

In my earlier post I wrote:

"You will need to replace the square brackets and the content within them"

that means:

REPLACE THE SQUARE BRACKETS

and

Replace the content within them

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>I tried it, couldn't get it to work. Must be doing something wrong.
> This is the code I put in:
[quoted text clipped - 50 lines]
>> > >>
>> > >> Eddie
skateblade - 11 Nov 2005 21:41 GMT
Well, thanks again for your patience.
Sorry to be a pain. I tried and it gave me a run error
This is what I  have now:
Private Sub savebutton_Click()
With ActiveDocument
   .SaveAs "C:\Documents and Settings\HP_Owner\My Documents\Word" &
.FormFields("ClientName").Result
   For i = 1 To .FormFields.Count
       .FormFields(i).Result = ""
   Next i
End With

End Sub

A box comes up and I get:
Run-time error '5941':
The requested member of the collection does not exist.
No idea what it means.
Obviously I'm missing something, nobody say a brain.
Thanks again Malcolm

> Remove the square brackets [ ].
>
[quoted text clipped - 64 lines]
> >> > >>
> >> > >> Eddie
Jonathan West - 11 Nov 2005 21:54 GMT
you need a closing backslash on the path.

  .SaveAs "C:\Documents and Settings\HP_Owner\My Documents\Word\" _
       & .FormFields("ClientName").Result

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> Well, thanks again for your patience.
> Sorry to be a pain. I tried and it gave me a run error
[quoted text clipped - 88 lines]
>> >> > >>
>> >> > >> Eddie
skateblade - 11 Nov 2005 21:43 GMT
PS if anybody would like me to send the file to look at let me know.
Malcolm

> Remove the square brackets [ ].
>
[quoted text clipped - 64 lines]
> >> > >>
> >> > >> Eddie
 
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.