Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-28-2022, 02:41 AM
hkrawick@gmail.com hkrawick@gmail.com is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 7 64bit Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Novice
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?
 
Join Date: Jul 2022
Posts: 15
hkrawick@gmail.com is on a distinguished road
Default Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?

I have created a word UserForm that has multiple checkboxes. I want the value of those checkboxes to appear on my word document next to a bookmark value. However, right now only one value is displayed on my document

Dim oCtrl As Control
Dim NeededForms As Range
Set NeededForms = ActiveDocument.Bookmarks("NeededForms").Range

For Each oCtrl In NeededForms1.Controls
If TypeName(oCtrl) = "CheckBox" Then
If oCtrl.Value = True Then
NeededForms.Text = oCtrl.Caption
Exit For
End If
End If
Next
Unload Me


Repaint
End Sub
Reply With Quote
  #2  
Old 07-28-2022, 04:10 AM
Guessed's Avatar
Guessed Guessed is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 10 Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

As written, the code should keep replacing the same range until it does the final caption (this happens faster than you can see). If you want it to keep adding then insert the text after the range or keep adding to the end or start of the range.
For example:
NeededForms.InsertAfter vbCr & oCtrl.Caption
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 07-28-2022, 04:32 PM
hkrawick@gmail.com hkrawick@gmail.com is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 7 64bit Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Novice
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?
 
Join Date: Jul 2022
Posts: 15
hkrawick@gmail.com is on a distinguished road
Default

Thank you for replying. I am new to vb code so I am unsure exactly where to insert your suggested line of code or if I need to omit some of mine. I want the caption of any checkbox that is checked to display on the document. Example: Form Needed: Signature form, Content form, Worklist form. What I get s just on forms captions displaying.
Reply With Quote
  #4  
Old 07-28-2022, 04:36 PM
Guessed's Avatar
Guessed Guessed is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 10 Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

It replaces the line that says
NeededForms.Text = oCtrl.Caption
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 07-29-2022, 05:39 PM
hkrawick@gmail.com hkrawick@gmail.com is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 7 64bit Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Novice
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?
 
Join Date: Jul 2022
Posts: 15
hkrawick@gmail.com is on a distinguished road
Default

It's still only putting one checkbox caption in. Not sure why?
Reply With Quote
  #6  
Old 07-30-2022, 04:44 AM
Guessed's Avatar
Guessed Guessed is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 10 Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

How many checkboxes were checked when the macro ran?

You need to post a document or template with the code and userform if you need someone to solve your problem.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 07-30-2022, 01:57 PM
hkrawick@gmail.com hkrawick@gmail.com is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 7 64bit Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Novice
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?
 
Join Date: Jul 2022
Posts: 15
hkrawick@gmail.com is on a distinguished road
Default Reply

I have all three checked and the middle checkbox is the only one that appears next to the bookmark when I check all three. The template is simple just has a bookmark where that information needs to go.
Reply With Quote
  #8  
Old 07-30-2022, 02:00 PM
hkrawick@gmail.com hkrawick@gmail.com is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 7 64bit Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Novice
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?
 
Join Date: Jul 2022
Posts: 15
hkrawick@gmail.com is on a distinguished road
Default

I also wanted to add a reset button to the template so you don't have to close the document and re-open it every time you want to use the user form again with a fresh document, but it doesn't appear that there are very good resources for vb coding where it pertains to the bookmarks. So I am up against that obstacle.
Reply With Quote
  #9  
Old 07-30-2022, 02:14 PM
hkrawick@gmail.com hkrawick@gmail.com is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 7 64bit Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Novice
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?
 
Join Date: Jul 2022
Posts: 15
hkrawick@gmail.com is on a distinguished road
Default Form

Attachment of a section of the form and its output only displaying the caption from the second box.
Attached Images
File Type: png Form and output.png (8.5 KB, 19 views)
Reply With Quote
  #10  
Old 07-30-2022, 02:55 PM
eduzs eduzs is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 10 Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2019
Expert
 
Join Date: May 2017
Posts: 262
eduzs is on a distinguished road
Default

Maybe because 'Exit for' once it finds a checkbox=true, the rest are not being analyzed.
__________________
Backup your original file before doing any modification.
Reply With Quote
  #11  
Old 07-30-2022, 04:46 PM
macropod's Avatar
macropod macropod is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 10 Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: VBA UserForm for Word Mulitple checkboxes not all displaying on document | MrExcel Message Board
For cross-posting etiquette, please read: A message to forum cross posters - Excelguru
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 07-31-2022, 04:50 PM
hkrawick@gmail.com hkrawick@gmail.com is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 7 64bit Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Novice
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?
 
Join Date: Jul 2022
Posts: 15
hkrawick@gmail.com is on a distinguished road
Default Reply

I had no idea MrExcel and MsOfficeForums were connected. I posted on MrExcel because I believed it was a completely different site and I am trying to get help. I had no intentions of Cross-posting.
Reply With Quote
  #13  
Old 07-31-2022, 04:52 PM
macropod's Avatar
macropod macropod is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 10 Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

They are different sites, which is the whole point. Please read the link I provided.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 07-31-2022, 04:52 PM
hkrawick@gmail.com hkrawick@gmail.com is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 7 64bit Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Novice
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?
 
Join Date: Jul 2022
Posts: 15
hkrawick@gmail.com is on a distinguished road
Default

The one displaying is the second on checked which I find odd. I would think it would have used the last one checked, but it always returns the text from the second box.
Reply With Quote
  #15  
Old 07-31-2022, 07:54 PM
hkrawick@gmail.com hkrawick@gmail.com is offline Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Windows 7 64bit Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Office 2016
Novice
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code?
 
Join Date: Jul 2022
Posts: 15
hkrawick@gmail.com is on a distinguished road
Default

I read through your message. I am very confused and new to these message boards. All in all, I am unsure why or how my internet activity is being monitored on a completely different site. All in all, I went elsewhere days after this post because the solution was not working. It is working now that the last person told me to remove the for statement.
Reply With Quote
Reply

Tags
checkboxes, word user form



Similar Threads
Thread Thread Starter Forum Replies Last Post
ms word document text translation using vba code pk_00 Word VBA 1 03-02-2020 03:11 PM
The Word userform checkbox (checked/unchecked) is not saved on the Application Quit matapagi2019 Word VBA 3 03-31-2019 02:29 AM
Word Userform is only displaying 1 text value on document and not all that are checked. VBA code? Creating a letter in Word, with text pulled from an Excel document based on selections in a userform TMAL Word VBA 6 12-15-2017 02:16 PM
Template opens with userform ; non-checked boxes should lead to deletion of corresp paragraphs samszaf Word 1 09-07-2015 09:52 AM
VBA Code in a UserForm module to delete a Command Button which opens the userform Simoninparis Word VBA 2 09-21-2014 03:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft