How do I save a file using the value entered in a text form field

G

Geoff

There was a post from a few years ago asking how to do this, to which the
following response was given.

Doug Robbins - Word MVP said:
With ActiveDocument
.SaveAs "SW_COA_" & .Formfields("Text2").Result & "_johnson.doc"
End With

I tried to do this with a module within a macro-enabled Word 2007 template,
but I get an error telling me "the requested member of the collection does
not exist".

If I go to the locals window, ActiveDocument isn't even there. Sorry, my
VisualBasic is a lot stronger within Access. But if I am running the code
from an open template with data, how can there not be an active document?

TIA
 
G

Graham Mayor

Frankly I would error trap this to ensure that the form field has been
filled before saving, but your error message reflects that your form does
not have a form field called "Text2".

Sub SaveForm()
With ActiveDocument
If .FormFields("Text2").Result <> "" Then
.SaveAs "SW_COA_" & .FormFields("Text2").Result & "_johnson.doc"
Else
MsgBox "Form field must be completed"
.FormFields("Text2").Select
End If
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
N

Nadihaha

Could this be used with dropdown boxes too? And could I ask it to source the
info from multiple drop down boxes?

Thanks
 
G

Graham Mayor

Dropdown boxes will always have a result, but it may not be the result you
want, however they can certainly be used in the same way eg

With ActiveDocument
If .FormFields("Text1").Result <> "" Then
.SaveAs .FormFields("Dropdown1").Result & _
.FormFields("Dropdown2").Result & _
.FormFields("Text1").Result & _
".doc"
Else
MsgBox "Form field must be completed"
.FormFields("Text1").Select
End If
End With

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
N

Nadihaha

Many Thanks. Not sure it's going to achieve quite what I require but I'll
give it a go anyway.
 

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