Need to have form field end up with data generated by macro that isrun on entry/exit

D

dedawson

I just had a Word form task dumped on me, which would not be a problem
if I had spent a lot of time working with forms in the past.

But I haven't.

I need to create a form field, run a macro on entry (or exit, if more
appropriate), and have the macro results end up in the form field when
I'm done. For example, a one line macro that places the result of
application.username into the field.

Its probably very obvious to most everyone, but right now I'm missing
it.

thanks in advance
david
 
J

Jean-Guy Marcil

dedawson was telling us:
dedawson nous racontait que :
I just had a Word form task dumped on me, which would not be a problem
if I had spent a lot of time working with forms in the past.

But I haven't.

I need to create a form field, run a macro on entry (or exit, if more
appropriate), and have the macro results end up in the form field when
I'm done. For example, a one line macro that places the result of
application.username into the field.

Its probably very obvious to most everyone, but right now I'm missing
it.

thanks in advance
david

I think it would be better if you took a step back and explained what you
actually need. You give an example, which might be necessary to your task,
but I am sure you need more than that. As stated, it is difficult to help
you with precise information because your needs are not all that clear...

What is "application.username? In the context of Word VBA, "application"
refers to Word itself, in which case the username would be the name you see
in the Personal Information tab of the Options under Tools. For this, you do
not need a macro, a single field will do the trick (Insert > Fields).
If you mean the network/Windows username, then this is a different story.

By the way, why does it have to be a "one-line macro"?

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

dedawson

Oops. In my hurry I guess I was a bit vague. What I'm doing is
creating a form to use in conducting peer reviews of engineering
documents. As each reviewer examines a document, he needs to populate
a number of form fields describing the defect he has found. Among the
fields will be some in which various chunks of free-text will entered
to describe the problem. Other fields will contain page numbers, line
numbers, the name of the reviewer, etc. The key issue is that for
each defect that is to be described, another iteration of the form
will need to be completed. To make the task easier on the reviewer, I
want to be able to populate some of the fields for him automatically.
His name would be one, hence the VBA snippet (one-line macro was a
quick, but not very clear, description)) application.username.
Similarly, I can use other pieces of VBA to gather other necessary
data; I just haven't stumbled upon the means of getting it into the
form field

I should also explain the general layout of the form. It is
essentially a table of 4 or 5 rows of various numbers of cells in a
Word document. Some cells contain labels describing what is to be
entered into the form fields in other cells. Each time a new defect
is to be logged, a new set of rows is added to the document, so that
when all is complete, there may be four or five pages of consecutive
sets of rows, each describing an individual defect. I can then write
code to process the table and extract review metrics.

thanks again,

david
 
D

dedawson

Oh good grief this is embarrassing. I knew I was tired, but not that
tired!

Sub GetUserName()
Selection = Environ("USERNAME")
End Sub


In Form Field Options:
Set Run Macro on Entry = GetUserName
Check Fill-in enabled


Sorry to waste your time.

david
 

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