From: PMuller on 21 Dec 2009 22:51 I have a complicated userform contained within a template. Once the userform is completed and the OK command button is selected the userform merges and populates. Within the template I have a series of cross references which I would like updated once the document populates although I'm not sure how to do this as the form unloads and then the document populates. Can someone please shed any light on how I might update fields once the template is has populated? Basically after the following is completed, then I want do something simple like a print preview so the cross references are populated. I'm just not certain how to run another macro after hitting OK. My OK command is as follows: Private Sub cmdOK_Click() ActiveDocument.Bookmarks("Ref").Range.Text = txtRef ActiveDocument.Bookmarks("Sender").Range.Text = txtSender ActiveDocument.Bookmarks("SendersTitle").Range.Text = txtSTitle If OptExistingClient = True Then ActiveDocument.Bookmarks("ClientStatus").Range.Text = "Paragraph 1" If OptNewClient = True Then ActiveDocument.Bookmarks("ClientStatus").Range.Text = "Paragraph 2" If OptARR_FeeEstimate = True Then InsertARR_FeeEstimate If OptARR_FeeEstimate = False Then RemoveARR_FeeEstimate If OptARR_HourlyRates = True Then InsertARR_HourlyRates If OptARR_HourlyRates = False Then RemoveARR_HourlyRates If OptOtherServices_FeeEstimate = True Then InsertOS_FeeEstimate If OptOtherServices_FeeEstimate = False Then RemoveOS_FeeEstimate If OptOtherServices_HourlyRates = True Then InsertOS_HourlyRates If OptOtherServices_HourlyRates = False Then RemoveOS_HourlyRates If CheckBoxOS_PreparationPayroll = True Then InsertOS_PreparationPayroll If CheckBoxOS_PreparationPayroll = False Then RemoveOS_PreparationPayroll If CheckBoxOS_ReviewWorkersComp = True Then InsertOS_ReviewWorkersComp If CheckBoxOS_ReviewWorkersComp = False Then RemoveOS_ReviewWorkersComp If CheckBoxOS_PreparationMonthlyDebtors = True Then InsertOS_PreparationMonthlyDebtors If CheckBoxOS_PreparationMonthlyDebtors = False Then RemoveOS_PreparationMonthlyDebtors If CheckBoxOS_PreparationFinancialStatements = True Then InsertOS_PreparationFinancialStatements If CheckBoxOS_PreparationFinancialStatements = False Then RemoveOS_PreparationFinancialStatements If CheckBoxOS_SuccessionPlanning = True Then InsertOS_SuccessionPlanning If CheckBoxOS_SuccessionPlanning = False Then RemoveOS_SuccessionPlanning If CheckBoxOS_BusinessRestructure = True Then InsertOS_BusinessRestructure If CheckBoxOS_BusinessRestructure = False Then RemoveOS_BusinessRestructure If CheckBoxOS_AccountingBookkeeping = True Then InsertOS_AccountingBookkeeping If CheckBoxOS_AccountingBookkeeping = False Then RemoveOS_AccountingBookkeeping If CheckBoxOS_GeneralBusiness = True Then InsertOS_GeneralBusiness If CheckBoxOS_GeneralBusiness = False Then RemoveOS_GeneralBusiness If OptCOBNE = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = "CO Name" If OptCO = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = "CO Name" If OptCOCFIN = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = "CO Name CFIN" If OptCOSEC = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = "CO Name SEC Limited" If OptCOWM = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = "CO Name WM" Selection.GoTo What:=wdGoToBookmark, Name:="Body" Unload Me End Sub
From: Doug Robbins - Word MVP on 21 Dec 2009 23:16 You can probably just include a command to update the fields in the document. If they are all in the body of the document ActiveDocument.Range.Fields.Update will do. If there are also fields in the header and footers, it is necessary to iterate through each of those and update the fields in their ranges, or a quick and easy way is just to use With ActiveDocument .PrintPreview .ClosePrintPreview End With -- Hope this helps, Doug Robbins - Word MVP Please reply only to the newsgroups unless you wish to obtain my services on a paid professional basis. "PMuller" <PMuller(a)discussions.microsoft.com> wrote in message news:4DACA8E1-427B-47F3-B6FB-4DBAEC0ABDA7(a)microsoft.com... >I have a complicated userform contained within a template. Once the >userform > is completed and the OK command button is selected the userform merges and > populates. > > Within the template I have a series of cross references which I would like > updated once the document populates although I'm not sure how to do this > as > the form unloads and then the document populates. Can someone please shed > any light on how I might update fields once the template is has populated? > > Basically after the following is completed, then I want do something > simple > like a print preview so the cross references are populated. I'm just not > certain how to run another macro after hitting OK. > > My OK command is as follows: > > Private Sub cmdOK_Click() > > ActiveDocument.Bookmarks("Ref").Range.Text = txtRef > ActiveDocument.Bookmarks("Sender").Range.Text = txtSender > ActiveDocument.Bookmarks("SendersTitle").Range.Text = txtSTitle > > If OptExistingClient = True Then > ActiveDocument.Bookmarks("ClientStatus").Range.Text = "Paragraph 1" > If OptNewClient = True Then > ActiveDocument.Bookmarks("ClientStatus").Range.Text = "Paragraph 2" > > If OptARR_FeeEstimate = True Then InsertARR_FeeEstimate > If OptARR_FeeEstimate = False Then RemoveARR_FeeEstimate > If OptARR_HourlyRates = True Then InsertARR_HourlyRates > If OptARR_HourlyRates = False Then RemoveARR_HourlyRates > If OptOtherServices_FeeEstimate = True Then InsertOS_FeeEstimate > If OptOtherServices_FeeEstimate = False Then RemoveOS_FeeEstimate > If OptOtherServices_HourlyRates = True Then InsertOS_HourlyRates > If OptOtherServices_HourlyRates = False Then RemoveOS_HourlyRates > > If CheckBoxOS_PreparationPayroll = True Then InsertOS_PreparationPayroll > If CheckBoxOS_PreparationPayroll = False Then RemoveOS_PreparationPayroll > If CheckBoxOS_ReviewWorkersComp = True Then InsertOS_ReviewWorkersComp > If CheckBoxOS_ReviewWorkersComp = False Then RemoveOS_ReviewWorkersComp > If CheckBoxOS_PreparationMonthlyDebtors = True Then > InsertOS_PreparationMonthlyDebtors > If CheckBoxOS_PreparationMonthlyDebtors = False Then > RemoveOS_PreparationMonthlyDebtors > If CheckBoxOS_PreparationFinancialStatements = True Then > InsertOS_PreparationFinancialStatements > If CheckBoxOS_PreparationFinancialStatements = False Then > RemoveOS_PreparationFinancialStatements > If CheckBoxOS_SuccessionPlanning = True Then InsertOS_SuccessionPlanning > If CheckBoxOS_SuccessionPlanning = False Then RemoveOS_SuccessionPlanning > If CheckBoxOS_BusinessRestructure = True Then InsertOS_BusinessRestructure > If CheckBoxOS_BusinessRestructure = False Then > RemoveOS_BusinessRestructure > If CheckBoxOS_AccountingBookkeeping = True Then > InsertOS_AccountingBookkeeping > If CheckBoxOS_AccountingBookkeeping = False Then > RemoveOS_AccountingBookkeeping > If CheckBoxOS_GeneralBusiness = True Then InsertOS_GeneralBusiness > If CheckBoxOS_GeneralBusiness = False Then RemoveOS_GeneralBusiness > > If OptCOBNE = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = > "CO Name" > If OptCO = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = > "CO > Name" > If OptCOCFIN = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text > = > "CO Name CFIN" > If OptCOSEC = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = > "CO Name SEC Limited" > If OptCOWM = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = > "CO Name WM" > > Selection.GoTo What:=wdGoToBookmark, Name:="Body" > > Unload Me > > End Sub > > > > >
From: Jay Freedman on 21 Dec 2009 23:20 On Mon, 21 Dec 2009 19:51:02 -0800, PMuller <PMuller(a)discussions.microsoft.com> wrote: >I have a complicated userform contained within a template. Once the userform >is completed and the OK command button is selected the userform merges and >populates. > >Within the template I have a series of cross references which I would like >updated once the document populates although I'm not sure how to do this as >the form unloads and then the document populates. Can someone please shed >any light on how I might update fields once the template is has populated? > >Basically after the following is completed, then I want do something simple >like a print preview so the cross references are populated. I'm just not >certain how to run another macro after hitting OK. > >My OK command is as follows: > [snip unneeded detail] You must have a macro that declares and shows the userform. (I say "must" because that's the only way to run a userform in Word.) Maybe it's Sub AutoNew or Sub Document_New or something else. When the userform's .Show method is called, control passes to the userform and its code. When the userform unloads, control returns to the next line of the macro -- and that's where you can insert the statements ActiveWindow.View = wdPrintPreview ActiveWindow.View = wdPrintView -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
From: Fumei2 via OfficeKB.com on 22 Dec 2009 15:47 I would like to point out that: If CheckBoxOS_SuccessionPlanning = True Then InsertOS_SuccessionPlanning If CheckBoxOS_SuccessionPlanning = False Then RemoveOS_SuccessionPlanning is two separate instructions, parsed and executed by VBA. If CheckBoxOS_SuccessionPlanning = True Then InsertOS_SuccessionPlanning Else RemoveOS_SuccessionPlanning End If Is ONE instruction. If CheckBoxOS_SuccessionPlanning is not True, then it is False. PMuller wrote: >I have a complicated userform contained within a template. Once the userform >is completed and the OK command button is selected the userform merges and >populates. > >Within the template I have a series of cross references which I would like >updated once the document populates although I'm not sure how to do this as >the form unloads and then the document populates. Can someone please shed >any light on how I might update fields once the template is has populated? > >Basically after the following is completed, then I want do something simple >like a print preview so the cross references are populated. I'm just not >certain how to run another macro after hitting OK. > >My OK command is as follows: > >Private Sub cmdOK_Click() > >ActiveDocument.Bookmarks("Ref").Range.Text = txtRef >ActiveDocument.Bookmarks("Sender").Range.Text = txtSender >ActiveDocument.Bookmarks("SendersTitle").Range.Text = txtSTitle > >If OptExistingClient = True Then >ActiveDocument.Bookmarks("ClientStatus").Range.Text = "Paragraph 1" >If OptNewClient = True Then >ActiveDocument.Bookmarks("ClientStatus").Range.Text = "Paragraph 2" > >If OptARR_FeeEstimate = True Then InsertARR_FeeEstimate >If OptARR_FeeEstimate = False Then RemoveARR_FeeEstimate >If OptARR_HourlyRates = True Then InsertARR_HourlyRates >If OptARR_HourlyRates = False Then RemoveARR_HourlyRates >If OptOtherServices_FeeEstimate = True Then InsertOS_FeeEstimate >If OptOtherServices_FeeEstimate = False Then RemoveOS_FeeEstimate >If OptOtherServices_HourlyRates = True Then InsertOS_HourlyRates >If OptOtherServices_HourlyRates = False Then RemoveOS_HourlyRates > >If CheckBoxOS_PreparationPayroll = True Then InsertOS_PreparationPayroll >If CheckBoxOS_PreparationPayroll = False Then RemoveOS_PreparationPayroll >If CheckBoxOS_ReviewWorkersComp = True Then InsertOS_ReviewWorkersComp >If CheckBoxOS_ReviewWorkersComp = False Then RemoveOS_ReviewWorkersComp >If CheckBoxOS_PreparationMonthlyDebtors = True Then >InsertOS_PreparationMonthlyDebtors >If CheckBoxOS_PreparationMonthlyDebtors = False Then >RemoveOS_PreparationMonthlyDebtors >If CheckBoxOS_PreparationFinancialStatements = True Then >InsertOS_PreparationFinancialStatements >If CheckBoxOS_PreparationFinancialStatements = False Then >RemoveOS_PreparationFinancialStatements >If CheckBoxOS_SuccessionPlanning = True Then InsertOS_SuccessionPlanning >If CheckBoxOS_SuccessionPlanning = False Then RemoveOS_SuccessionPlanning >If CheckBoxOS_BusinessRestructure = True Then InsertOS_BusinessRestructure >If CheckBoxOS_BusinessRestructure = False Then RemoveOS_BusinessRestructure >If CheckBoxOS_AccountingBookkeeping = True Then InsertOS_AccountingBookkeeping >If CheckBoxOS_AccountingBookkeeping = False Then >RemoveOS_AccountingBookkeeping >If CheckBoxOS_GeneralBusiness = True Then InsertOS_GeneralBusiness >If CheckBoxOS_GeneralBusiness = False Then RemoveOS_GeneralBusiness > >If OptCOBNE = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = >"CO Name" >If OptCO = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = "CO >Name" >If OptCOCFIN = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = >"CO Name CFIN" >If OptCOSEC = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = >"CO Name SEC Limited" >If OptCOWM = True Then ActiveDocument.Bookmarks("CO_Entity").Range.Text = >"CO Name WM" > >Selection.GoTo What:=wdGoToBookmark, Name:="Body" > > Unload Me > >End Sub -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.aspx/word-programming/200912/1
|
Pages: 1 Prev: Using code to hide format of form field until needed. Next: Blank Userform |