Convert drop down lists and fields to text

  • Thread starter Rod from Corrections
  • Start date
R

Rod from Corrections

I have created two templates for forms that folks on my worksite fill out on
a daily basis. Both are protected so that the users only have the ability
to fill in the fields on the forms. There are a couple of drop-down lists
and the rest are standard fields for the user to fill in text.

Is it possible to have a macro (or perhaps there is another method) run when
the user exits the final field so that all of the fields are converted to
regular text? As it is now, once they are finished, the drop-down fields
remain and they can continue to tab through the fields and make changes.
Although I don't need as much security as locking the entire form and
preventing future editing, it would be nice to at least have the entire
completed form like regular text, rather than them being able to still access
the drop down list.
 
D

Dian D. Chapman, MVP

Yes.

All form fields have an option to run a macro on either entrance or
exit from the field. So you could write a procedure that would convert
all the form field contents to text in each location and then add it
into the EXIT field of the last field (double click the form field to
view the properties and see the ENTRY and EXIT input boxes).

Now to do what you want, you'll have to write a routine that would
loop through each form field...capture the contents of that
field...then delete the form field in that location and replace it
with the current variable value from that field. That can be done
without too much trouble...but I don't have the time now to write up
that code. So you'll have to work that out.

However, if you'd prefer to just disable all the form fields so they
can't change them...which would leave them in place, but just not
allow them to change them any longer after one pass...I DO happen to
have that code handy. So if that's an option for you, just use the
code below and it'll disable all the form fields in a file. Just add
the name of this macro into the exit of the last one.

Sub DisableAllFields()
Dim ff As FormField
Dim i As Integer
Dim strName As String

i = 1

For Each ff In ActiveDocument.FormFields
strName = ActiveDocument.FormFields(i).Name
With ActiveDocument.FormFields(strName)
.Enabled = False
End With
i = i + 1
Next ff

End Sub

Note that if you also want code to enable them again, just change
..Enabled = True. Create a second macro for YOU only that reenables
them, should you need to do that.

Hope this helps...

Dian D. Chapman
Technical Consultant, Microsoft MVP
MOS Certified, Editor/TechTrax

Free MS Tutorials: http://www.mousetrax.com/techtrax
Free Word eBook: http://www.mousetrax.com/books.html
Optimize your business docs: http://www.mousetrax.com/consulting
Learn VBA the easy way: http://www.mousetrax.com/techcourses.html
 
R

Rod from Corrections

Thanks, Dian. I hadn't thought about disabling the fields. That's
definitely an option.

One small wrinkle: is it possible to disable only the drop down lists but
not disable the regular text entry fields? On consulting with the users,
they want to disable the drop-downs, which are easy to accidentally change,
but still have the ability to edit the regular fields to correct typos, etc.
 
D

Dian D. Chapman, MVP

Yes...but then use THIS code, instead. This version below has an added
If...Then statement to first check to see if the current form field is
actually a drop down. If so, THEN it disables it, otherwise it'll skip
it and continue the loop to the end of the doc hunting out each drop
down only.

(NOTE...if you type in that line yourself, you'll see the intellisense
code show you all the form field terms so you can change it if you
wanted to switch to other form fields. Just be sure to also remember
to add the End If in there or you'll get an error cos' that new
statement won't be closed.)

Sub DisableAllFields()
Dim ff As FormField
Dim i As Integer
Dim strName As String

i = 1

For Each ff In ActiveDocument.FormFields
If ff.Type = wdFieldFormDropDown Then
strName = ActiveDocument.FormFields(i).Name
With ActiveDocument.FormFields(strName)
.Enabled = False
End With
End If
i = i + 1
Next ff

End Sub


Have fun! ;-)

Dian D. Chapman
Technical Consultant, Microsoft MVP
MOS Certified, Editor/TechTrax

Free MS Tutorials: http://www.mousetrax.com/techtrax
Free Word eBook: http://www.mousetrax.com/books.html
Optimize your business docs: http://www.mousetrax.com/consulting
Learn VBA the easy way: http://www.mousetrax.com/techcourses.html
 
J

Jay Freedman

Hi Rod,

Here's your wrinkled macro :)

Sub DisableDropdowns()
Dim ff As FormField
For Each ff In ActiveDocument.FormFields
If ff.Type = wdFieldFormDropDown Then
ff.Enabled = False
End If
Next
End Sub

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

Rod from Corrections

Thanks so much, Dian! I sure do appreciate you taking the time to answer my
query. Your code worked like a charm, although so did Jay's, so I opted to
use his simpler version.
 
R

Rod from Corrections

Thanks, Jay. It's so good of folks like you and Dian to take your valuable
time and answer queries from folks like me.

I found that both versions of the code from you and Dian worked. I opted to
use your simpler version. It works like a charm - exactly what I needed.

Thanks again!
 
D

Dian D. Chapman, MVP

NO problem...glad the info helped.

And yes, if it's a choice between my code and Jay's...unless it's ADO
connectivity<g>...take Jay's. Who do you think I steal all my code
from!<vbeg>

Dian ~
 
D

Dian D. Chapman, MVP

Just an FYI in my defense<g>...know that I passed this code from my
own library and the reason I have the added NAME capture in there
(which I was too lazy to remove) is cos' in another part of the code I
can opt to create a doc listing all the names of the Form Fields in a
form, along with their settings.

I do a lot of clean up for clients with forms. So the FIRST thing I do
to get a handle of what the user has done to date is create/print a
list of all their form fields with property details so I can figure
out who's on first. ;-)

Dian ~
 

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