Userforms and drop downs

S

Susan B. Quinn

I am obviously missing something in this whole coding game. I have done case
statements for drop down menus. I have set up option boxes that insert auto
texts.

I now want to insert an auto text based on the choice made from a drop down
menu. But the code while appearing to make sense doesn't work. What am I
missing???



Select case

Sub OnExitrecognise_DD()
Dim recogniseBks As Bookmarks
Dim recognise_Rng1 As Word.Range
Set recognise_Bks = ActiveDocument.Bookmarks
Set recognise_Rng1 = recognise_Bks("recognise_range").Range
ActiveDocument.Unprotect
Select Case ActiveDocument.FormFields("recognise_bm").Result
Case Is = "develop"
Set recongise_Rng1 =
..AttachedTemplate.AutoTextEntries("insert_text").Insert _
(Where:=recognise_Rng1, RichText:=True)

End Select
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True
End Sub

Nothing happens. It just skips over the bookmark without inserting anything.

Yours in code frustration.
 
G

Greg Maxey

Susan,

It is hard to tell what exactly it is that you are trying to do. I think
you want to insert the autotext 'insert_text' in a bookmark range if the
result of a dropdown is develop.

Try:

Sub OnExitrecognise_DD()
Dim recognise_Bks As Bookmarks
Dim recognise_Rng1 As Word.Range
Set recognise_Bks = ActiveDocument.Bookmarks
Set recognise_Rng1 = recognise_Bks("recognise_range").Range
With ActiveDocument
.Unprotect
Select Case .FormFields("recognise_bm").Result
Case Is = "develop"
Set recognise_Rng1 = recognise_Bks("recognise_range").Range
recognise_Rng1.Text = .AttachedTemplate.AutoTextEntries("insert_text")
.Bookmarks.Add "recognise_range", recognise_Rng1
End Select
.Protect wdAllowOnlyFormFields, NoReset:=True
End With
End Sub
 
J

Jean-Guy Marcil

Susan B. Quinn was telling us:
Susan B. Quinn nous racontait que :
I am obviously missing something in this whole coding game. I have
done case statements for drop down menus. I have set up option boxes
that insert auto texts.

I now want to insert an auto text based on the choice made from a
drop down menu. But the code while appearing to make sense doesn't
work. What am I missing???



Select case

Sub OnExitrecognise_DD()
Dim recogniseBks As Bookmarks
Dim recognise_Rng1 As Word.Range
Set recognise_Bks = ActiveDocument.Bookmarks
Set recognise_Rng1 = recognise_Bks("recognise_range").Range
ActiveDocument.Unprotect
Select Case ActiveDocument.FormFields("recognise_bm").Result
Case Is = "develop"
Set recongise_Rng1 =
.AttachedTemplate.AutoTextEntries("insert_text").Insert _
(Where:=recognise_Rng1, RichText:=True)

End Select
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True
End Sub

Nothing happens. It just skips over the bookmark without inserting
anything.

Yours in code frustration.

Except for one little thing your code looks fine.

Remove the "." (dot) before AttachedTemplate.

Just to be sure I tested as is (after removing the dot) and it worked on my
machine with Word 2003.

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

Jezebel

Sub OnExitrecognise_DD()

ActiveDocument.Unprotect
Select Case ActiveDocument.FormFields("recognise_bm").Result
Case "develop"
AttachedTemplate.AutoTextEntries("insert_text").Insert _
Where:= ActiveDocument.Bookmarks("recognise_range").Range, _
RichText:=True

Case else
End Select

ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True

End Sub
 
S

Susan B. Quinn

I will try it again. But I did remove the period and it still didn't work. I
had used the same reasoning as you.

Thank you for your assistance
 
S

Susan B. Quinn

Thank you to all of you for your help. But we were never going to override
user error. It was "D"evelop not "d"evelop that was what was causing the
problem!!!

I had checked the spelling but not the use of capitals.

Susan
 
J

Jezebel

If you insert the line "Option Compare Text" at the top of the module (right
under "Option Explicit") you wouldn't have to worry about it.
 

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