|
|
I have a userform and have put bookmarks into my document to insert the data entered into the userform.
Some of the fields in the userform will not always be used everywhere in a document.
For instance, I have fields Atty1 and Atty2 which are used several places in the document. In one place, both will be used, in another place it is possibly to only use Atty1. I put a checkmark next to each of the fields and called them Atty1ck and Atty2ck respectively.
Basically, if Atty1ck is checked, insert Atty1 data into document and if Atty2ck is checked insert that data as well.
Both fields are used in the document, inserted the first time as a bookmark and subsequent times as a cross-reference to the bookmarks, but there is one place where only one of the fields MAY be used. How do I reference the code so that if the checkbox value = true, insert the data; if it is false do not insert the data AND remove the placeholder for the data in the document (to avoid blank lines).
I hope this isn't too confusing! Thank you, in advance, for any assistance!
|
|
Something like
With ActiveDocument.Bookmarks("bookmarkname") If ChkControl.Value = True Then .Range.InsertBefore TxtControl.Text Else .Range.Paragraphs(1).Range.Delete End If End With
-- Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis.
Doug Robbins - Word MVP
"Jeri" <Jeri[ at ]discussions.microsoft.com> wrote in message news:0501B575-B367-4B30-996F-CD72C7C3B85C[ at ]microsoft.com...
[Quoted Text] >I have a userform and have put bookmarks into my document to insert the >data > entered into the userform. > > Some of the fields in the userform will not always be used everywhere in a > document. > > For instance, I have fields Atty1 and Atty2 which are used several places > in > the document. In one place, both will be used, in another place it is > possibly to only use Atty1. I put a checkmark next to each of the fields > and > called them Atty1ck and Atty2ck respectively. > > Basically, if Atty1ck is checked, insert Atty1 data into document and if > Atty2ck is checked insert that data as well. > > Both fields are used in the document, inserted the first time as a > bookmark > and subsequent times as a cross-reference to the bookmarks, but there is > one > place where only one of the fields MAY be used. How do I reference the > code > so that if the checkbox value = true, insert the data; if it is false do > not > insert the data AND remove the placeholder for the data in the document > (to > avoid blank lines). > > I hope this isn't too confusing! Thank you, in advance, for any > assistance!
|
|
Doug ~
This looks great. I'll give it a try. But let me ask an obvious newbie question (or two):
1. Do I put the code within the existing code that is populating the document? Something like:
With ActiveDocument .Bookmarks("CaseNo").Range _ .InsertBefore CaseNo .Bookmarks("Day").Range _ .InsertBefore Day .Bookmarks("Month").Range _ .InsertBefore Month .Bookmarks("Year").Range _ .InsertBefore Year End With
With.ActiveDocument.Bookmark(Atty2) If Atty2ChkControl.Value = True Then .Range.InsertBefore Atty2.Text Else .Range.Paragraphs(1).Range.Delete End If End With
(the bookmark and the control on the userform have the same name)
2. In the portion of the code .Range.Paragraphs(1).Range.Delete How do I represent the paragraph that is to be deleted? Do I change the (1) to the bookmark name?
Thank you so much for your assistance with this!
Jeri
"Doug Robbins - Word MVP" wrote:
[Quoted Text] > Something like > > With ActiveDocument.Bookmarks("bookmarkname") > If ChkControl.Value = True Then > .Range.InsertBefore TxtControl.Text > Else > .Range.Paragraphs(1).Range.Delete > End If > End With > > > > > -- > Hope this helps. > > Please reply to the newsgroup unless you wish to avail yourself of my > services on a paid consulting basis. > > Doug Robbins - Word MVP > > "Jeri" <Jeri[ at ]discussions.microsoft.com> wrote in message > news:0501B575-B367-4B30-996F-CD72C7C3B85C[ at ]microsoft.com... > >I have a userform and have put bookmarks into my document to insert the > >data > > entered into the userform. > > > > Some of the fields in the userform will not always be used everywhere in a > > document. > > > > For instance, I have fields Atty1 and Atty2 which are used several places > > in > > the document. In one place, both will be used, in another place it is > > possibly to only use Atty1. I put a checkmark next to each of the fields > > and > > called them Atty1ck and Atty2ck respectively. > > > > Basically, if Atty1ck is checked, insert Atty1 data into document and if > > Atty2ck is checked insert that data as well. > > > > Both fields are used in the document, inserted the first time as a > > bookmark > > and subsequent times as a cross-reference to the bookmarks, but there is > > one > > place where only one of the fields MAY be used. How do I reference the > > code > > so that if the checkbox value = true, insert the data; if it is false do > > not > > insert the data AND remove the placeholder for the data in the document > > (to > > avoid blank lines). > > > > I hope this isn't too confusing! Thank you, in advance, for any > > assistance! > > >
|
|
The code that you have would work, but you could modify it to:
With ActiveDocument .Bookmarks("CaseNo").Range _ .InsertBefore CaseNo .Bookmarks("Day").Range _ .InsertBefore Day .Bookmarks("Month").Range _ .InsertBefore Month .Bookmarks("Year").Range _ .InsertBefore Year With .Bookmark(Atty2) If Atty2ChkControl.Value = True Then .Range.InsertBefore Atty2.Text Else .Range.Paragraphs(1).Range.Delete End If End With End With
You do not need to replace the (1) with anything as what is being deleted is the first (1) paragraph in the Range of the bookmark Atty2 -- Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis.
Doug Robbins - Word MVP
"Jeri" <Jeri[ at ]discussions.microsoft.com> wrote in message news:F4F7C588-EA0A-48E4-9A13-A22A4E3C932D[ at ]microsoft.com...
[Quoted Text] > Doug ~ > > This looks great. I'll give it a try. But let me ask an obvious newbie > question (or two): > > 1. Do I put the code within the existing code that is populating the > document? Something like: > > With ActiveDocument > .Bookmarks("CaseNo").Range _ > .InsertBefore CaseNo > .Bookmarks("Day").Range _ > .InsertBefore Day > .Bookmarks("Month").Range _ > .InsertBefore Month > .Bookmarks("Year").Range _ > .InsertBefore Year > End With > > With.ActiveDocument.Bookmark(Atty2) > If Atty2ChkControl.Value = True Then > .Range.InsertBefore Atty2.Text > Else > .Range.Paragraphs(1).Range.Delete > End If > End With > > (the bookmark and the control on the userform have the same name) > > 2. In the portion of the code > .Range.Paragraphs(1).Range.Delete > How do I represent the paragraph that is to be deleted? Do I change the > (1) > to the bookmark name? > > Thank you so much for your assistance with this! > > Jeri > > "Doug Robbins - Word MVP" wrote: > >> Something like >> >> With ActiveDocument.Bookmarks("bookmarkname") >> If ChkControl.Value = True Then >> .Range.InsertBefore TxtControl.Text >> Else >> .Range.Paragraphs(1).Range.Delete >> End If >> End With >> >> >> >> >> -- >> Hope this helps. >> >> Please reply to the newsgroup unless you wish to avail yourself of my >> services on a paid consulting basis. >> >> Doug Robbins - Word MVP >> >> "Jeri" <Jeri[ at ]discussions.microsoft.com> wrote in message >> news:0501B575-B367-4B30-996F-CD72C7C3B85C[ at ]microsoft.com... >> >I have a userform and have put bookmarks into my document to insert the >> >data >> > entered into the userform. >> > >> > Some of the fields in the userform will not always be used everywhere >> > in a >> > document. >> > >> > For instance, I have fields Atty1 and Atty2 which are used several >> > places >> > in >> > the document. In one place, both will be used, in another place it is >> > possibly to only use Atty1. I put a checkmark next to each of the >> > fields >> > and >> > called them Atty1ck and Atty2ck respectively. >> > >> > Basically, if Atty1ck is checked, insert Atty1 data into document and >> > if >> > Atty2ck is checked insert that data as well. >> > >> > Both fields are used in the document, inserted the first time as a >> > bookmark >> > and subsequent times as a cross-reference to the bookmarks, but there >> > is >> > one >> > place where only one of the fields MAY be used. How do I reference the >> > code >> > so that if the checkbox value = true, insert the data; if it is false >> > do >> > not >> > insert the data AND remove the placeholder for the data in the document >> > (to >> > avoid blank lines). >> > >> > I hope this isn't too confusing! Thank you, in advance, for any >> > assistance! >> >> >>
|
|
|