| View previous topic :: View next topic |
| Author |
Message |
rhodestransit Power User

Joined: 17 Mar 2011 Posts: 91
|
Posted: Wed Apr 18, 2012 5:54 am Post subject: Save with auto file name |
|
|
I am creating a form with text boxes that a user can complete and save to a folder.
To make the process easier is there a way i can have a save button that will save the form using a text field as the file name?
for example if the the form is an accident report it will user the name of the person who had the accident as the file name. |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Wed Apr 18, 2012 8:54 am Post subject: |
|
|
My test file has a User Field named Name containing a name. This macro will not work with any other type of field.
| Code: | Sub UserFieldAsFileName_Writer
On Error goto EH
oDoc = ThisComponent
TFM = oDoc.getTextFieldMasters
If TFM.hasByName("com.sun.star.text.fieldmaster.User.Name") then
field = TFM.getByName("com.sun.star.text.fieldmaster.User.Name")
filename = field.content
Else MsgBox "No such field exists." : END
EndIf
url = ConvertToURL("C:\Users\John\Documents\" & filename & ".odt")'Insert Your Desired Directory Path.
oDoc.StoreAsURL(url,Array())
oDoc.Modified = false 'avoid Save being called if doc closed without further edits.
Exit Sub 'end normal execution.
EH: 'error handler.
MsgBox "You may have illegal file name characters in the file name shown below." & Chr(13)_
& Chr(13) & filename,,"AN ERROR OCCURRED"
End Sub |
|
|
| Back to top |
|
 |
rhodestransit Power User

Joined: 17 Mar 2011 Posts: 91
|
Posted: Wed Apr 18, 2012 9:13 am Post subject: |
|
|
| Thanks for the macro, I dont seem to have a field listed for "user" is that an add on? |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Wed Apr 18, 2012 10:43 am Post subject: |
|
|
| Quote: | | I dont seem to have a field listed for "user" | Insert > Fields > Other > Variables tab. |
|
| Back to top |
|
 |
rhodestransit Power User

Joined: 17 Mar 2011 Posts: 91
|
Posted: Thu Apr 19, 2012 6:58 am Post subject: |
|
|
Ok thanks I found that now,
What do i put in the Value field?
I was hoping to get a box to use as a field on the form |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Thu Apr 19, 2012 7:27 am Post subject: |
|
|
| Quote: | | What do i put in the Value field? | Nothing.
The easiest way to get a box is Insert > Frame but you can also do View > Toolbars > Form Controls and use the Text Box. |
|
| Back to top |
|
 |
rhodestransit Power User

Joined: 17 Mar 2011 Posts: 91
|
Posted: Thu Apr 19, 2012 12:53 pm Post subject: |
|
|
| I dont know what in doing wrong, it will save but it will not save it with a file name. |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Thu Apr 19, 2012 4:58 pm Post subject: |
|
|
| Quote: | Quote:
What do i put in the Value field?
Nothing.
| MY BAD! I thought I was in another tread.
You put what you want the file name to be in the Value field. |
|
| Back to top |
|
 |
rhodestransit Power User

Joined: 17 Mar 2011 Posts: 91
|
Posted: Fri Apr 20, 2012 3:11 am Post subject: |
|
|
OK, thanks.
Its not going to work how i want then, I was hoping for a form with a save button that an office member can complete and save without having to insert fields.
Thanks for your help |
|
| Back to top |
|
 |
|