add username to a Word Form

C

cgijag

I'm creating a document template that contains text fields. Currently i have
a text field where our foreman enter their name. Is there a way to put a
field on this form that autofills the username into it? I've read about
Application.Username function which displays the user info which would be
perfect. My question is how do you add this function to the form. via vba
in a text box field? Thanks.
 
J

Jay Freedman

cgijag said:
I'm creating a document template that contains text fields.
Currently i have a text field where our foreman enter their name. Is
there a way to put a field on this form that autofills the username
into it? I've read about Application.Username function which
displays the user info which would be perfect. My question is how do
you add this function to the form. via vba in a text box field?
Thanks.

There are (many) other ways, but I'll suggest writing an AutoNew() macro in
the template. If the "bookmark name" of the text form field is Name, then
the macro would be

Sub AutoNew()
ActiveDocument.FormFields("Name").Result = Application.UserName
End Sub

The AutoNew macro runs automatically when a new document is created from the
template (and if the macro is in the specific template used for these forms,
it will affect only these forms).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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