Using email from a form

I am sending an email from a sub-sub form. This part of the code works on one computer but not the other computer. Is there a better way to call that field? The parent form is titled MainForm

objEmailMessage.To = Me.Parent.Parent.[Email]

Thanks!
cansevinAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
try

objEmailMessage.To = Forms!MainForm.[Email]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nick67Commented:
Unless you reuse the subforms in many places (doubtful!) this is one time I wouldn't torture yourself about hard-coding a name.

objEmailMessage.To = Forms!MainForm![Email]

should be just fine
0
Rey Obrero (Capricorn1)Commented:
it is better to name control different from the name of the field it is bound to.
i.e., change the control Email to txtEmail

objEmailMessage.To = Forms!MainForm.txtEmail
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Nick67Commented:
@Rey
Why?
The default for all bound controls is the fieldname.
I have never understood why anyone goes to the scutwork of renaming everything.
Was it a problem pre-Access 2003/
It never has been a problem A2003+
0
cansevinAuthor Commented:
Still not working. Any ideas?

I've tried:

        objEmailMessage.To = Forms!MainForm.[Email]

and
objEmailMessage.To = Forms!MainForm.txtEmail


The who code is:

Set objOutlook = CreateObject("Outlook.Application")
        Set objEmailMessage = objOutlook.CreateItem(olMailItem)
        objEmailMessage.To = Forms!MainForm.txtEmail
        objEmailMessage.Subject = sSubj
        objEmailMessage.htmlBody = sBody & vbCrLf & vbCrLf
        objEmailMessage.Display
        objEmailMessage.Attachments.Add "C:\Invoices\CustomerInvoices.pdf"

Open in new window

0
Nick67Commented:
First things first
What contains the email address?
A control on a form named MainForm?

Throw in a MsgBox and let's see
If It is a control, then

MsgBox Forms!MainForm!NameOfTheControlWithTheEmailInIt

Subsititute in the control's name

That should toss back the email address.
Does it?
0
cansevinAuthor Commented:
Sorry guys... didn't have an email in the box. The first answer solved it.
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
It never has been a problem A2003+
That is not correct. I worked on a project last week in 2010 that refused to see a textbox until I changed the name to txCustName. Prior to that - when it was named the same as the Field - the code would fail reliably. The machine was fully updated for both Windows and Office, but it still would not see the field on the form.

I recreated the form with just a handful of fields, and tried again - same result.

I based the form on a different table, and tried again - same result.

I change the name from "CustName" to "txCustName" and it worked.

Note this was not an "upgraded" project. This was one created from scratch in Access 2010, in the .accdb format.
0
Nick67Commented:
Weird.
I've never seen that yet, and I must have well over a thousand bound controls where the fieldname and controlname are the same running for the last 10 years in A2003+ without ever encountering that.  Was it run-of-the-mill code and a control bound to a DAO object's field?

Note that I only use the !bang operator where it is required  -- in other word, places where .dot notation doesn't work (Forms!SomeForm!SomeControl, but never Me!Anything etc)
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Yes, it was vanilla code in a DLookup statement, and the object was a standard Textbox bound to an underlying field in a typical form. The author had not renamed the controls, and the code simply refused to see the value. I mucked around for a bit, removed and replaced the textbox, etc etc - and finally changed the control name and the code began to work. I actually changed it back to see if it would fail, and it did so immediately.

I had the same issue occur in a 2007 application about a year ago (which is what prompted me to changed the name). Same scenario, except that code was trying to open a DAO Recordset filtered on a value being pulled from a form.

Of course, like you I've seen innumerable instances where the Control name is exactly the same as the bound Field name, and it works flawlessly. In the case of the 2007 issue I spent a considerable amount of time insuring the database was "clean" (i.e. compact/decompile/import to new, etc etc) and that the environment was "clean" (i.e. all updates, rebooted, only running 2007, etc). Nothing helped. I moved the 2007 database to my own machine, and it failed there in 2007, 2010, and 2013.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.