Autogenerate file names from Word Form inputs

A

Autobahn

I am creating a form that will be sent out with people who have laptops
but no connection to a centralized server. They will be creating many unique
documents from the standard forms and we are standardizing the name of the
resulting .doc files to be created from three fields on the form. LastName,
Firstame, Date. The Lastname and FirstName fields are input while the date
is an autogenerated field. I want to add a button to the field that will
save the document automatically with the proper file naming convention. Here
is the code I am currently using, but I know part of it is wrong and I have
no idea how to grab the information out of an autogenerated field:

XXXXXXXX
Sub Save()

Dim objWord As Word.Application

'Note: I know this next line is wrong, what should I set this to?
Set objWord = CurrentApplication

With objWord
..Visible = True

'Move to each bookmark and insert text from the form.
..ActiveDocument.Bookmarks("Text1").Select
..Selection.Text = (CStr(Forms!MainData!FirstName))
..ActiveDocument.Bookmarks("Text2").Select
..Selection.Text = (CStr(Forms!MainData!LastName))
End With

'Note: I did not try to input the date field, any help would be great.
Dim FName As String
FName = Forms!MainData!FirstName & " " & Forms!MainData!LastName & ".doc"
objWord.ActiveDocument.SaveAs FileName:=FName

End Sub
XXXXXX
 
A

Autobahn

I was being WAY too tricky. I took a step back and just did it all from
a local document perspective and came up with this code that works. The
numbers in the code refer to the relative positions of the fields in my
document.

XXXXXXX
Private Sub NameSave_Click()

Dim FName As String

ActiveDocument.Bookmarks(3).Select

FName = FName & Selection.Text & " "

ActiveDocument.Bookmarks(4).Select

FName = FName & Selection.Text & " "

ActiveDocument.Fields(5).Select

FName = FName & Selection.Text & ".doc"

ActiveDocument.SaveAs FileName:=FName

End Sub
XXXXXX
 

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