![]() |
#1
|
|||
|
|||
![]()
Hello everyone, I am not a pro, so I am coming to the gurus because I desperately need your help using a combination of spin button and Do loop. I am using Do Loop because I do not have a set number.
I created a spin button to allow users to enter the number of specific paragraphs to add to the document. The spin button works fine, problem is getting the info from the document based on the number selected from the spin button. Example, Question - How many HOA paragraphs do you need? Answer - User selects 4 with the spin button. The merge must now insert the paragraph from another document called HOASSOCiation.doc four times. Here is what I tried but did not work. Private Sub UserForm_Initialize() With Spnhoa .Min = 1 .Max = 20 .Value = 1 ' Initialize TextBox Tbhoa.Text = .Value End With End Sub Then, I need the following to happen Private Sub HOA () Dim number As Long Dim min As Long Dim max As Long min = 1 max = 20 Do number = Tbcondog Loop Until number: >= min And number <= max Selection.GoTo What:=wdGoToBookmark, Name:="HOASSOCIATION" With ActiveDocument.Bookmarks .DefaultSorting = wdSortByName .ShowHidden = True End With ChangeFileOpenDirectory "C:\HOA\MERGES\" Selection.InsertFile FileName:= _ "C:\HOA\MERGES\Association.doc" _ , Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False Selection.WholeStory End Sub Further The paragraph reads: MERGEFIELD Defendant_1 has access to the property........ Each time the paragraph is inserted, the mergefield Defendant_1 also changes. If user selects 4, then the first paragraph will merge with Mergefield Defendant_1, the second paragraph will merge with mergefield Defendant_2, the third paragraph will merge with mergefield Defendant_3 and the fourth paragraph will merge with mergefield Defendant_4. How do I make all this happen? I tried {SEQ Defendant_\*NUMERIC\*MERGEFORMAT} but that did not work. Help ![]() ![]() |
#2
|
||||
|
||||
![]()
Perhaps you could explain what you're trying to achieve. It looks like it might be a mailmerge with a variable number of records, for which there are already plenty of solutions, but it's not clear from your post whether that's actually what you're trying to achieve.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Ok, I attached a file and hope this helps.
|
#4
|
||||
|
||||
![]()
Yes, I understand what you're doing, but that doesn't tell me what you're trying to achieve. For example, what are the mergefields for? Are they just being used as placeholders or are you actually proposing to do a mailmerge?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
I do not know all the technical terms, I am just learning so I will attempt to respond and hope I do not complicate this further.
Yes I am proposing to do a mailmerge once the user has entered data. I run a macro that opens the userform shown in my previous post. Once the user enters the numbers and hit ok, then the doc merges and pulls the mergefield info from the database AND repeats this per the number(s) entered by the user. I hope this makes sense. If not, what do you suggest? I am on edge because my deadline is fast approaching. Sorry, I am not sure what you mean by placeholders. |
#6
|
||||
|
||||
![]()
So where do the data come from and how are they structured?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
Thank you for responding and for you help. I believe you are referring to my statement of "when user enter data..." when you ask about the data? I was referring to the number user inserts at the spin box in the userform. Everything from the proprietary database works fine, I have no problem with that. My only problem and main concern is repeating information/paragraphs in the doc per the number selected. That, I can't get to work. I can get it to work if I use If.. Then... Else but that's a lot to write. If 20 is selected, I don't want to use If... Then... Else 10 times. There has to be an easier way using either the Loop or For next and I am trying to do one of them.
|
#8
|
||||
|
||||
![]()
The reason I asked about the data source is that you probably don't need your userform to insert anything; all that's needed is a knowledge of the data structure. After that, it's simply a matter of inserting the appropriate field coding into the document. Once.
It appears you're working with a database that has multiple Defendant fields per record and the max # of Defendant fields is 20. In that case, you could use a document like the attached. The field coding in it provides for all 20 Defendant fields, but only those that have data will actually generate any output. Simply attach it as a mailmerge main document to your database, then Finish the merge and send the output to a new document.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]()
Thank you for your respond. The attachment will work perfectly if, the inserted paragraph applies to every defendant but it does not apply to all defendents. There has to be a question that asks How many additional paragraphs are needed. Users check the files, to see how many of the defendants in the database needs the paragraphs and selects the number. Based on that number, the amount of paragraphs are inserted. It may only apply to the first three defendants, or maybe the first and third only.
|
#10
|
||||
|
||||
![]() Quote:
Your userform provides no means of inputting that a particular paragraph is required for the first and third defendants only - your form design means anything output for the third defendant would necessarily be output for the first and second defendants also.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
![]()
Because I ran out of time, I used a Combo box with the If, Else Then option. I know there is an easier way, there has to be an easier way but I had to get the doc live. It is lengthy but it gets the job done.
|
#12
|
||||
|
||||
![]()
Until you're prepared to answer the question I asked in my previous post, no progress is likely...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
maximus123 | PowerPoint | 1 | 08-04-2015 05:33 AM |
How to copy format of a column using spin button | Tyberian1988 | Excel Programming | 2 | 03-10-2014 10:09 PM |
![]() |
hannu | Excel | 3 | 11-14-2013 01:42 AM |
![]() |
revans611 | Word | 1 | 11-29-2010 11:57 AM |
Help with Combination function | sanasath | Excel | 0 | 12-13-2005 07:24 AM |