Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dedawson - 10 Jan 2008 01:05 GMT
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
Jean-Guy Marcil - 10 Jan 2008 01:56 GMT
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.
[quoted text clipped - 11 lines]
> 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"?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

dedawson - 10 Jan 2008 03:13 GMT
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
dedawson - 10 Jan 2008 04:59 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.