The error message means what it says. You have a ".To" expression outside a
With ... End With block. Therefore, Outlook has no idea what object's To
property your code refers to. Use either:
With Item
> To = "moyerw"
End With
or
Item.To = "moyerw"
Some suggestions:
-- If a control is bound to an Outlook field/property, refer to the
field value not the control value in your code; see
http://www.outlookcode.com/article.aspx?ID=38.
-- Once you have the value, use a Select Case ... End Select block to
evaluate it and perform other actions, not a series of If ... End If
statements.
-- When setting the value of To, use the full email address or an alias
that is uniquely resolvable to an address.
Sue Mosher
"Wanda" <Wanda> wrote in message
news:99F1249D-A02D-4378-9F75-DC5869D025D2@microsoft.com...
> Hi Sue:
> This works good to bring up a message. My code was:
> ***********
> Sub cmdTest_Click()
> Set objTab1 = Item.GetInspector.ModifiedFormPages("General")
> Set objControls = objTab1.Controls("cmbProv")
> IF objTab1.Controls("cmbProv")= "Saskatchewan" THEN
> msgBox "Hi"
> End If
> End Sub
> ***************
> When I change msgBox "hi" to:
> .TO = "moyerw"
> a message comes up saying "Invalid or unqualified reference". Can I put
> the address in the TO (recipient) field this way?
> Thank you.
> Wanda
> "Sue Mosher [MVP]" wrote:
>
> > See http://outlookcode.com/article.aspx?ID=38 for information on the
> > events
> > you can use to change the To field when the user selects from your combo
> > box. The details depend on whether the combo box is bound to an Outlook
> > property and, of so, which one.
>
>> "Wanda" <Wanda> wrote in message
> > news:21B05773-C8A5-4571-8F1B-60DF82923901@microsoft.com...
> > >I have created a custom form. I have a drop down menu to be able to
> > >select
> > > a province. Is there a way when a certain province is selected that
> > > it
> > > put
> > > a certain address in the TO field on the form? When I put the code in
> > > and
> > > we try to send the form, it comes saying "There must be a least one
> > > name
> > > or
> > > distribution list in the To, CC or BCC box". If the form has
> > > something
> > > in
> > > one of the fields (TO, CC or BCC) and then with the code, it will add
> > > the
> > > code I put in ... but originally, I don't want anything in the name
> > > fields.
> > > Is there a way around this? We are use XP-SP3 and Outlook 2003, sp3.
> > > Thank you.
> > > Wanda