|
-
May 2nd, 2005, 01:10 PM
#1
Thread Starter
Member
Inserting value from dropdown into bookmark
I want to take the value selected from a dropdown and insert it elsewhere in the text. I have added a second bookmark so as not to change the value of the original because if the value is "single" I will concatenate it to be "single person". Elsewise it remain as is.
Do I need to cast somehow in order to put a formfield variable value into a bookmark/string/range?? variable value?
-
May 2nd, 2005, 11:36 PM
#2
Re: Inserting value from dropdown into bookmark
I take it that this is a Word UserForm.
Upon the combo clikc or a command button click event you can append the value in the bookmark with the selection in the combo.
Its easier to do this upon a command button click.
VB Code:
'Behind UserForm1
Private Sub CommandButton1_Click()
ActiveDocument.Bookmarks("Test").Range.Text = ActiveDocument.Bookmarks("Test").Range.Text & " " & UserForm1.ComboBox1.Text
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 3rd, 2005, 03:02 PM
#3
Thread Starter
Member
Re: Inserting value from dropdown into bookmark
I'm sorry I wasn't more specific. Yes, this is Word 2003. And I'm not using the dropdown from a user form (this time). I ended up doing this:
VB Code:
Dim vStatus As String
Dim vStatSelect As Integer
vStatSelect = ActiveDocument.FormFields("Status").DropDown.Value
Select Case vStatSelect
Case 2
ActiveDocument.Bookmarks("StatusP").Range.Text = "single person"
Case 3
ActiveDocument.Bookmarks("StatusP").Range.Text = "widow"
Case 4
ActiveDocument.Bookmarks("StatusP").Range.Text = "widower"
End Select
End Sub
But I get an error on the ActiveDocument.Bookmarks... line & I don't have a clue why. I've also tried ActiveDocument.Bookmarks.("StatusP").Range.InsertAfter "single person"
There's something I'm missing here (like a course in VBA)
-
May 3rd, 2005, 04:05 PM
#4
Re: Inserting value from dropdown into bookmark
Verify that your bookmarks are named correctly and exist.
If you .InsertAfter then it not really "in" the bookmark but rather after the location of the bookmark.
Last edited by RobDog888; May 3rd, 2005 at 04:31 PM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 3rd, 2005, 04:20 PM
#5
Thread Starter
Member
Re: Inserting value from dropdown into bookmark
If I see the bookmark when I'm within the document & go to Insert Bookmark, then am I assured it exists? Is it possible it has a space in the name that might be throwing it off? Is there a technique to creating the bookmark and placing it in the text that I should be following to ensure it existence?
-
May 3rd, 2005, 04:29 PM
#6
Thread Starter
Member
Re: Inserting value from dropdown into bookmark
Actually, now that I pay closer attention to the error that is generated before I went into Debug Mode, it says
Run Time Error 6124:
You are not allowed to edit this region because document protection is in effect.
Did I set this up in a way that is locking the form from playing the macros? If so, how do I correct this?
-
May 3rd, 2005, 04:34 PM
#7
Re: Inserting value from dropdown into bookmark
Go to Tools > Protect Document...
And check out any protection that may be turned on. If not then it could be that the form is in design mode and not
run mode when you are trying to run the macro code.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 4th, 2005, 10:52 AM
#8
Thread Starter
Member
Re: Inserting value from dropdown into bookmark
I do have protection turned on for the section that contains the dropdowns & checkboxes so that they will be enabled to limit editing to filling in forms. It would seem counterproductive if this in turn disables the macros that those features run when they cannot be enabled without the document protection. I've seen something about using XML or Active X or (some such thing) checkboxes & dropdowns, however, that allow the document to be unprotected and still have these features enabled. Is this the direction I should be taking instead, or is there something else that I'm missing about the standard features?
-
May 10th, 2005, 12:09 PM
#9
Thread Starter
Member
Re: Inserting value from dropdown into bookmark
After playing around with this, if I write into my code to unprotect the document for the duration of the macro, it updates the bookmarks properly. However, then it resets the dropdown to the default one. If I take the unprotect code out of the document, the dropdown keeps the value selected, but I get the debug error that I cannot edit the document because it is protected. However, I have the document divided into 2 sections: the top part where the options are is protected & the bottom part where the text to be affected by the option is unprotected. What do I need to do to make my selection stick but still allow the document to be modified by the macros run in conjunction with the dropdowns?
VB Code:
Sub StatusM()
'
' StatusM Macro
' Macro recorded 4/29/2005 by Heather Lore
'
' If the value of the dropdown is "single" then the areas
' in the document that this should populate will also include
' the text " person"
Dim vStatSelect As Integer
Dim vStat As String
vStatSelect = ActiveDocument.FormFields("Status").DropDown.Value
ActiveDocument.Unprotect
Select Case vStatSelect
Case 2
vStat = "single person"
Case 3
vStat = "widow"
Case 4
vStat = "widower"
End Select
Selection.GoTo What:=wdGoToBookmark, Name:="StatusP"
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.InsertAfter vStat
ActiveDocument.Bookmarks.Add Range:=Selection.Range, _
Name:="StatusP"
ActiveDocument.Protect Type:=wdAllowOnlyFormFields
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|