Hi Susan
> a) which one is "more" correct <vbg>?
> MultiPage1.Value = MultiPage1.Item("pgAdditional").Index
> or
> .MultiPage1.Value = 2
Six of one and half a dozen of the other. If the page in your multipage
named "pgAdditional" is the 3rd page (ie has an .Index of 2) then
MultiPage1.Item("pgAdditional").Index
will resolve to 2.
And so
MultiPage1.Value = MultiPage1.Item("pgAdditional").Index
will have the same effect as
MultiPage1.Value = 2
In some cases, the first method would be marginally 'safer' because, if you
change the order of your pages, then the code will still work and will still
display the page named "pgAdditional" even if it's now, say, page 7. On the
other hand, if you use the MultiPage1.Item("pgAdditional") construct, and
you change the name of your page, then you'll have to remember to change
this line of code, too.
I don't like using the names of controls without explicitly telling VBA what
control it is. So I would do either:
Me.MultiPage1.Value = 2 OR Me.MultiPage1.Item("pgAdditional").Index
or
With Me
.MultiPage1.Value = 2 OR .MultiPage1.Item("pgAdditional").Index
End With
> b) you guys are saying i don't need to do this, correct?
> Dim pgAdditional As Control
> Dim pgData As Control
Without going through your code in detail, it's hard to say whether you need
these or not. However, make sure that you put
Option Explicit
at the top of every module, form and class. You can get the VBE to do this
automatically for you if you do Tools > Options and on the Editor tab, tick
"Require variable declaration".
> c) since i am ultimately going to be pasting data from the user form
> into documents, i searched the newsgroup & found this style - is it
[quoted text clipped - 5 lines]
> perhaps it would better be defined as
> vName = Me.MultiPage1.Value("2").txtName.Text ?
Neither of those lines of code will work, for various reasons. But let's
ignore that and get on with what you actually need to do.
I'm assuming that frmGenerateMortgages is the name of your userform. That
is, this is the name that appears in the Project Explorer. As a general
rule, do *not* use that name anywhere in the code of the form itself.
I'm assuming that txtName is a text box.
Then the code above seems to be trying to store the text in that text box in
a Word Variable. That may be what you want, but it won't insert the text
into your document. But if you do want a Word Variable, and if txtName is a
textbox, then you need something like:
Dim vName As Word.Variable
Set vName = ActiveDocument.Variables.Add(Name:="Name of my variable")
vName.Value = Me.txtName.Text
If you then want the value of the Variable to appear in the document, do
ctrl-F9 and within the braces that Word gives you, type DOCVARIABLE "Name
of my variable".
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
> Shauna & Tony
> many thanks! that makes a lot more sense. a few more
[quoted text clipped - 22 lines]
> many thanks for your patience & help.
> susan
Tony Strazzeri - 01 Oct 2006 17:24 GMT
I only have two comments to add.
> Hi Susan
>
> > a) which one is "more" correct <vbg>?
> > MultiPage1.Value = MultiPage1.Item("pgAdditional").Index
I prefer to use the page name as I find it easier to recognise and
remember as distinct from a number which as Shauna says can change. If
you change the page name you will get a runtime error.
> > c) since i am ultimately going to be pasting data from the user form
> > into documents, i searched the newsgroup & found this style - is it
> > correct?:
> >
> > Dim vName As Variable
> > vName = frmGenerateMortgages.MultiPage1.pgData.txtName.Text
Don't confuse Word Document variables with program variables.
Dim vName -defines a program variable as a varient data type (because
the actal dtat type has not been specified).
Dim vName As String - defines a variable that will contain text data.
Cheers
TonyS.
Susan - 01 Oct 2006 17:39 GMT
i appreciate all your help, you two! i'm not @ work today (sunday) so
i can't look @ my code directly. what i am specifically trying to do:
the user form will let users input the specific information that goes
into the blank mortgages. the mortgages are already set up with text
form fields and REF fields to repopulate the data (at the moment i just
use them as tabbed forms, but each project can have 2-4 mortgages, &
i'm tired of retyping the same info over & over). i have named the
document form fields the same names as the user form textboxes......
so, txtName in the user form (ultimately is supposed to) correspond
with txtName bookmark in the document.
once i get it to work with one mortgage, then the 10 or so check boxes
(after extensive coding & testing) will allow the program to pull up
each individual mortgage document, insert the data where necessary,
save it with a specific name (probably using the txtName field), print,
close that document, and open the next one.
i realize this is a VERY ambitious project but i feel you don't learn
anything if you don't try! :D i've got the userform up & running, &
thanks to your help i've got that AHC multipage working (that one
mortgage has some additional information required that the others don't
use).
i really don't want to post the whole code & have you guys "fix" it for
me; i'd rather try to do each part on my own & just ask for help when
i'm stuck. at this point i'm trying to figure out how to dim each user
form textbox; as a variable, as a string? one is a date, so that's
easy, and the numbers are obviously integers. when i get to work
tomorrow i'll look @ your suggestions & see how i can implement them.
thanks again & hope you're enjoying your weekend!!
susan
also, actually @ this point this is in the wrong newsgroup....... i
should repost to word.vba.
:D
susan