#16
|
||||
|
||||
Perhaps you could start by explaining what you're trying to achieve. Dropdowns aren't unique to userforms - there are also formfield dropdowns and content control dropdowns & comboboxes, all of which can be inserted into a document and none of which requires a userform.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#17
|
|||
|
|||
Quote:
I'm making a general word template for specifying which quality tests to perform on a given production item. The template will also be filled with test results and final score. Hence it will be sort of a summary for a given item and how well it passed the tests. I want the the dropdown list to be a list of standardized tests including a short description, e.g.: test1 - description1, test2 - description 2, test3 - description3, test4 - description4... etc. A total of approximately 50 individual tests: For a given item i want to be able to select/highlight a number of tests from the drop down list (e.g test1, test4 and test5) The selected test (name) should then appear as entries in a column of a table, one test name per row, either immediately when selecting the test or after the push of a button, such as in your example. Other columns of the table are blank placeholders for test description, results and additional remarks. Something like this: Capture.PNG Hope this explains sufficiently. Best regards Martin |
#18
|
||||
|
||||
What you're suggesting appears to require the table to have as many rows as there are possible choices from the dropdown, which could end up leaving most rows empty in some cases. It would be possible, however, to conditionally add rows to the table so only as many rows are created as are needed. That said, you might care to explore something like: https://www.msofficeforums.com/word-...html#post38461, perhaps with the subsequent rows only including dropdown items that haven't already been selected.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#19
|
|||
|
|||
Quote:
Unfortunately i'm not able to wrap my head around this. I'm simply too unexperienced with coding. I understand what you're suggesting, but i don't know how to do it. I don't know how to make the selections from the multiselect listbox appear in a table or make/apply a macro that adds rows. I don't know what content control is either (mentioned in the thread you linked to). Sorry. Best regards |
#20
|
||||
|
||||
The document attached to the post in the link I gave you has a working document with content controls and the necessary macro coding. You should download it and see how it works. We can discuss modifications once you decide you want to use that approach.
Even for what you've described in post #17 a macro would be required. Indeed, a macro is required even to populate the listbox you were proposing to use - and that would make the setup much harder for inexperienced users to maintain.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#21
|
|||
|
|||
Quote:
I don't know how to make the table work. I can view the code alright, but i don't know how to activate/run it. I tried pressing "run" in VBA editor but it then asks to create a macro. Upon doing so i end up with an empty module. I don't know where to start... |
#22
|
||||
|
||||
Did you read the instructions in the post itself?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#23
|
|||
|
|||
Quote:
Edit: Probably should have added, the list is on a userform and does not contain any external data. |
#24
|
||||
|
||||
In that case, you would replace:
MsgBox StrOut with code like: Call UpdateBookmark("bookmark_name", StrOut) where 'bookmark_name' is the name of the bookmark you want to update, plus add the following sub to the same code module: Code:
Sub UpdateBookmark(StrBkMk As String, StrTxt As String) Dim BkMkRng As Range With ActiveDocument If .Bookmarks.Exists(StrBkMk) Then Set BkMkRng = .Bookmarks(StrBkMk).Range BkMkRng.Text = StrTxt .Bookmarks.Add StrBkMk, BkMkRng End If End With Set BkMkRng = Nothing End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#25
|
|||
|
|||
So something like this? This gives me an error: Compile error expected end sub.
Code:
Option Explicit Sub Document_Open() With ListBox1 .Clear .MultiSelect = fmMultiSelectMulti .AddItem "Accupuncturist" .AddItem "Chiropractor" .AddItem "Dietician" .AddItem "Massage Therapist" .AddItem "Naturopath" .AddItem "Osteopath" .AddItem "Psychologist/Social worker" .AddItem "Physiotherapist" .AddItem "Podiatrist/Chiropractor" .AddItem "Speech Therapist" End With End Sub Private Sub CommandButton1_Click() Dim i As Long, StrOut As String For i = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(i) Then StrOut = StrOut & ListBox1.List(i) & vbCr End If Next i Call UpdateBookmark("bm1", StrOut) Sub UpdateBookmark(StrBkMk As String, StrTxt As String) Dim BkMkRng As Range With ActiveDocument If .Bookmarks.Exists(StrBkMk) Then Set BkMkRng = .Bookmarks(StrBkMk).Range BkMkRng.Text = StrTxt .Bookmarks.Add StrBkMk, BkMkRng End If End With Set BkMkRng = Nothing End Sub |
#26
|
||||
|
||||
No - the 'UpdateBookmark' needs to be a separate sub - you now have one sub inside another.
Code:
Private Sub CommandButton1_Click() Dim i As Long, StrOut As String For i = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(i) Then StrOut = StrOut & ListBox1.List(i) & vbCr End If Next i Call UpdateBookmark("bm1", StrOut) End Sub Sub UpdateBookmark(StrBkMk As String, StrTxt As String) Dim BkMkRng As Range With ActiveDocument If .Bookmarks.Exists(StrBkMk) Then Set BkMkRng = .Bookmarks(StrBkMk).Range BkMkRng.Text = StrTxt .Bookmarks.Add StrBkMk, BkMkRng End If End With Set BkMkRng = Nothing
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#27
|
|||
|
|||
Ok that works on the test document you posted, thank you. Now I can't seem to get it to work with my userform I have created. Would it be too much to ask to help put this together? It's mostly working but not quite there.
I have a few text unput boxes along with the multiselect list. I can't seem to get them to work together. I got the list working and the text boxes linked to bookmarks but when I add the code you posted to my userform it won't run. This is what I have on my userform Code:
Private Sub CommandButton1_Click() Dim bmdate As Range Set bmdate = ActiveDocument.Bookmarks("bmdate").Range bmdate.Text = Me.TextBox1.Value Dim bmname As Range Set bmname = ActiveDocument.Bookmarks("bmname").Range bmname.Text = Me.TextBox3.Value Dim bmlicense As Range Set bmlicense = ActiveDocument.Bookmarks("bmlicense").Range bmlicense.Text = Me.TextBox2.Value Dim bmaddress As Range Set bmaddress = ActiveDocument.Bookmarks("bmaddress").Range bmaddress.Text = Me.TextBox4.Value Dim bmfname As Range Set bmfname = ActiveDocument.Bookmarks("bmfname").Range bmfname.Text = Me.TextBox5.Value Dim bmcase As Range Set bmcase = ActiveDocument.Bookmarks("bmcase").Range bmcase.Text = Me.TextBox6.Value Dim bminspection As Range Set bminspection = ActiveDocument.Bookmarks("bminspection").Range bminspection.Text = Me.TextBox7.Value Dim bmcdate As Range Set bmcdate = ActiveDocument.Bookmarks("bmcdate").Range bmcdate.Text = Me.TextBox8.Value Dim bmctime As Range Set bmctime = ActiveDocument.Bookmarks("bmctime").Range bmctime.Text = Me.TextBox9.Value Me.Repaint UserForm1.Hide End Sub Private Sub UserForm_Initialize() TextBox1.Value = Format(Date, "mm/dd/yyyy") With ListBox1 .AddItem "D1 Failure to obtain a dealer license or dealing in vehicles without a valid license. Section 248(5)" .AddItem " Failure to obtain a salvage vehicle agent license. Section 248e(1)" .AddItem "D2 Failure to renew license. Business open. No vehicles bought or sold. Section 248(5)" .AddItem "D3 Failure to renew license. Business open. Vehicles bought or sold. Section 248(5)" .AddItem "D4 Failure to obtain a supplemental license. Section 248(7" .AddItem "D5 Failure to amend license information." .AddItem " Main location. Section 248(6)" .AddItem " Supplemental location. Section 248(7)" .AddItem "D6 Failure to comply with inventory loan requirements. Section 235b" .AddItem "D7 Exceeding authority granted by license. Section 248(8)" .AddItem "D8 Failure to meet established place of business requirements." .AddItem " A & B Dealers. Section 14(2)" .AddItem " W Dealers. Section 14(3)" .AddItem " R, C, F, & H Dealers. Section 14(1)" .AddItem "D9 Improper use of temporary registration." .AddItem " Gray-shaded area on RD-108 not completed or not properly completed. Section 217(6)" .AddItem " Issued more than one BFS-4. Section 226a(1)" .AddItem " BFS-4 sold outside of vehicle purchase, missing from inventory, used for personal use, on a vehicle not in inventory or when not permitted. Section 256" .AddItem "D10 Improper temporary registration recordkeeping. Sections 251(5) & 251(7)" .AddItem "D11 Failure to have police book or washout system." .AddItem " A, B, D & W Dealers. Section 251(1)" .AddItem " C & R Dealers. Section 251(9)" .AddItem " E Dealer. Section 251(6)" .AddItem " F Dealer. Section 251(10)" .AddItem " G Dealer. Section 251(8)" .AddItem " H Dealer. Section 251(11)" .AddItem " Scrap metal processors not required to be licensed. Section 251(5)" .AddItem "D12 Failure to maintain police book or washout system." .AddItem " Information required. Section 251(2)" .AddItem " Maintained for 5 years and available for inspection. Section 251(7)" .AddItem "D13 Proper sales tax not submitted with RD-108. Section 815" .AddItem "D14 Misrepresenting a vehicle as new, demonstrator, executive, manufacturer, leased or used. Section 248a" .AddItem "D15 Records not available for inspection during reasonable or established business hours. Sections 251(5) & 251(7)" .AddItem "D16 Failure to make application for title and registration in purchaser's name within 15 days of vehicle delivery. Section 217(4)" .AddItem "D17 Improper use of dealer plates." .AddItem " Service car, wrecker or allowing misuse. Section 244(6)" .AddItem " More than 72 hours for vehicle delivery. Section 244(9)" .AddItem " More than 72 hours for a test drive. Section 244(10)" .AddItem " Allowing another, not entitled, to use special plate. Section 256" .AddItem "D18 Failure to have properly assigned certificate of title in immediate possession." .AddItem " Assigned title with the odometer information properly completed. Section 235(1)" .AddItem " Shall not accept an odometer statement or title which has not been completely filled in by the transferor. Section 233a(4)" .AddItem "D19 Temporary registration records not available." .AddItem " Failure to present BFS-4 log for inspection or have log. Section 251(7)" .AddItem "D20 Failure to provide copies of a document at time of signing. Section 251a" .AddItem "D21 Failure to properly complete RD-108." .AddItem " Vehicle description (make, body style, model year, miles, special use boxes, weight or fee category). Section 217(1)(b)" .AddItem " Applicant's title, security interest name and address, accessories to the vehicle. Section 217(1)(c)" .AddItem " BFS-4 not recorded. Section 226a(3)" .AddItem " Name and address of seller and buyer, vehicle info, $$, description of trade-in, amount of vehicle insurance, type of insurance, charge for BFS-4, other charges and purpose, RD-108 dated, but not later than the actual date of delivery. Original and all copies identical info. Seller furnishes statement, signed by seller or seller's agent and buyer, filed w/SOS by seller. Section 251(3)" .AddItem "D22 Failure to apply for in-transit registration for out-of-state retail consumer taking delivery of vehicle in this state. Section 226(10)" .AddItem "D23 Failure to adhere to business hours on file with Secretary of State. Section 248a(2)" .AddItem "D24 Odometer alteration. Section 233a(6)" .AddItem "D25 Fraudulent act in connection with selling or otherwise dealing in vehicles. Section 249(d)" .AddItem "D26 Miscellaneous." .AddItem "D27 Improper odometer disclosure." .AddItem " No odometer disclosure. Section 233a(1)" .AddItem " Signing title as buyer and seller. Section 233a(3)" .AddItem "D28 Failure to maintain odometer disclosure records. Section 233a(11)" .AddItem "D30 Possession of a stolen vehicle. Section 254" .AddItem "D31 Failure to deliver title upon transfer of a vehicle to a dealer or consumer." .AddItem " To a dealer. Section 235(3)" .AddItem " To a consumer. Section 234(2)" .AddItem "D32 Selling or offering for sale a new vehicle without a franchise. Section 249(c)" .AddItem "D33 Violation of probation agreement." .AddItem "D34 Violation of suspension agreement." .AddItem "D35 Failure to properly complete broker's fee agreement. R 257.189" .AddItem "D36 Failure to give copy of broker's fee agreement. R 257.189" .AddItem "D37 Failure to properly complete broker purchase agreement. R 257.188" .AddItem "D38 Failure to give copy of broker purchase agreement. R 257.188" .AddItem "D39 Failure to disclose identity as a broker. R 257.187" .AddItem "D40 Salvage pool release vehicle before title issued. Section 217f" .AddItem "D41 Failure to apply for salvage or scrap title within 5 days. Section 217c(4)" .AddItem "D42 Failure to properly prepare TR-9 Scrap Vehicle Inventory. Section 217c(18)" .AddItem "D43 Failure to forward copies of TR-9 with the vehicle. Section 217c(18)" .AddItem "D44 Failure to forward titles to the Secretary of State. Section 217c(18)" .AddItem "D45 Failure to have major component parts record (SOS-426). " .AddItem " G Dealers. Section 251(8)" .AddItem " C & R Dealers. Section 251(9)" .AddItem " H Dealers. Section 251(11)" .AddItem "D46 Failure to maintain major component parts record (SOS-426)." .AddItem " G Dealers. Section 251(8)" .AddItem " C & R Dealers. Section 251(9)" .AddItem " H Dealers. Section 251(11)" .AddItem "D47 Failure to assign number to major component part." .AddItem " G Dealers. Section 251(8)" .AddItem " C & R Dealers. Section 251(9)" .AddItem " H Dealers. Section 251(11)" .AddItem "D48 Failure to give proper salvage vehicle disclosure. R 257.253" .AddItem "D49 Foreign alteration." .AddItem "D50 Former branded title status washed. Section 217(1)" .AddItem "D51 Failure to amend salvage vehicle agent license. Section 248e(7)" .AddItem "D52 Scrap titled vehicle issued clear title in Michigan or other state. " .AddItem " Class R, C, F, G, E, H or D who removes a scrap vehicle from this state for the purpose of rebuilding, or selling to a person other than a scrap metal processor. Section 217c(22)" .AddItem " Class R, C, F or H who removes a scrap vehicle from this state for the purpose of rebuilding or has sold the unit for the purpose of rebuilding. 249a(2)(e)" .AddItem "D53 Salvage pool/auction sold vehicle to other than former owner, or licensed salvage agent of an automotive recycler, or foreign salvage dealer. Section 248c(3)" .AddItem "D54 Failure to disclose previous damage on new vehicle. Section 233b" .AddItem "D55 Altering or using false or altered registration or title assignment." .AddItem " Improper use of title or registration. Section 256" .AddItem " Alters title or registration with fraudulent intent. Section 257(1)(a)" .AddItem " Holds or uses such document knowing the same to have been altered, forged, or falsified. Section 257(1)(d)" .AddItem " Knowingly possess, sell or offer false, counterfeit or stolen title or registration. Section 257(1)(e)" .AddItem "D56 Failure to maintain a properly executed dealer surety bond with good and sufficient surety (A, B, & D Dealers). Section 248(2)" End With lbl_Exit: Exit Sub End Sub Private Sub CommandButton1_Click() Dim i As Long, StrOut As String For i = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(i) Then StrOut = StrOut & Me.ListBox1.List(i) & vbCr End If Next i Call UpdateBookmark("bmviolations", StrOut) End Sub Sub UpdateBookmark(StrBkMk As String, StrTxt As String) Dim BkMkRng As Range With ActiveDocument If .Bookmarks.Exists(StrBkMk) Then Set BkMkRng = .Bookmarks(StrBkMk).Range BkMkRng.Text = StrTxt .Bookmarks.Add StrBkMk, BkMkRng End If End With Set BkMkRng = Nothing End Sub |
#28
|
||||
|
||||
Given that you have two CommandButton1_Click subs, it's hardly surprising it doesn't work. You need to sort out which CommandButton each relates to.
As for your first CommandButton1_Click sub, you don't need any of your Dim statements and lines like: Set bmdate = ActiveDocument.Bookmarks("bmdate").Range bmdate.Text = Me.TextBox1.Value These could all be reduced to lines like: Call UpdateBookmark("bmdate", TextBox1.Value)
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#29
|
|||
|
|||
Well I only have one button so I guess that does make sense that it doesn't work.
Bear with me, I'm still learning as I go. So how would I go about incorporating the code to make it all print on the form when I hit the button? I don't know how to integrate the 2 sections with the CommandButton_1Click heading into one so it will work. |
#30
|
||||
|
||||
So have just one CommandButton1_Click sub with code like:
Code:
Private Sub CommandButton1_Click() Dim i As Long, StrOut As String Call UpdateBookmark("bmdate", TextBox1.Value) Call UpdateBookmark("bmname", TextBox3.Value) Call UpdateBookmark("bmlicense", TextBox2.Value) 'etc. For i = 0 To ListBox1.ListCount - 1 If ListBox1.Selected(i) Then StrOut = StrOut & ListBox1.List(i) & vbCr End If Next i Call UpdateBookmark("bm1", StrOut) End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
form, multi drop down |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Change color according with dropdown selection | spk | Word VBA | 43 | 07-31-2022 03:51 PM |
Auto text after selection from Dropdown menu | trainsy | Word | 2 | 06-04-2014 04:43 AM |
block selection in dropdown list | Intruder | Excel | 2 | 01-10-2013 10:20 AM |
Dropdown selection value | coconutt | Word VBA | 5 | 09-13-2012 05:23 PM |
Autofill a form which is contingent on a dropdown selection. | biffle0764 | Word | 2 | 05-09-2012 12:54 PM |