For, code for button to save and clear form fields

S

skateblade

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
 
E

Edward Thrashcort

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
 
S

skateblade

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
 
D

Doug Robbins - Word MVP

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


--
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
 
S

skateblade

Thanks a lot it looks great, I will try it.

Malcolm

Doug Robbins - Word MVP said:
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


--
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

skateblade said:
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
 
S

skateblade

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

skateblade said:
Thanks a lot it looks great, I will try it.

Malcolm

Doug Robbins - Word MVP said:
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


--
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

skateblade said:
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
Save/Save-as dialog.

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

Eddie
 
J

Jonathan West

Doug mentioned that you don't want the square brackets in the pathname.


--
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


skateblade said:
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

skateblade said:
Thanks a lot it looks great, I will try it.

Malcolm

Doug Robbins - Word MVP said:
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


--
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.
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
Save/Save-as dialog.

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

Eddie
 
D

Doug Robbins - Word MVP

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

--
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

skateblade said:
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

skateblade said:
Thanks a lot it looks great, I will try it.

Malcolm

Doug Robbins - Word MVP said:
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


--
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.
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
Save/Save-as dialog.

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

Eddie
 
S

skateblade

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

Doug Robbins - Word MVP said:
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

--
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

skateblade said:
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

skateblade said:
Thanks a lot it looks great, I will try it.

Malcolm

:

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


--
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.
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
Save/Save-as dialog.

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

Eddie
 
S

skateblade

PS if anybody would like me to send the file to look at let me know.
Malcolm

Doug Robbins - Word MVP said:
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

--
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

skateblade said:
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

skateblade said:
Thanks a lot it looks great, I will try it.

Malcolm

:

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


--
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.
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
Save/Save-as dialog.

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

Eddie
 
J

Jonathan West

you need a closing backslash on the path.

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

--
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

skateblade said:
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

Doug Robbins - Word MVP said:
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

--
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

skateblade said:
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.

Malcolm

:

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


--
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.
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
Save/Save-as dialog.

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

Eddie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top