command button issue

metisbear
NewLounger
Posts: 7
Joined: 05 Jun 2014, 15:14

command button issue

Post by metisbear »

Hi all. I added a command button to my Word 2010 document to submit a form to an email address. When I click the button it behaves as expected, except that, when it opens Outlook and attaches the form to the email, the email address to which I need it to go isn't filled in. I am new to this, so it's probably something simple, but I just can't get it to put that email address in and I'm frustrated by it. Here is the code it's using:

Private Sub CommandButton2_Click()
Options.SendMailAttach = True
ActiveDocument.SendMail
End Sub


Thanks!

Bear

User avatar
Leif
Administrator
Posts: 7213
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: command button issue

Post by Leif »

Welcome to Eileen's Lounge!

Does the third method at Send an email from Word give you any help?
Leif

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: command button issue

Post by Rudi »

Welcome from me too...

There is no command in your code that collects (or requests) an email address, so it will not be able to populate the newly created email with a recipients address. The code will need to collect the email address captured in your form and write it into the email using code similar to what Leif points you to, or it will need to be prompted for at the time of running....
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

metisbear
NewLounger
Posts: 7
Joined: 05 Jun 2014, 15:14

Re: command button issue

Post by metisbear »

Thanks, guys!

@Leif: I tried the code but, when I click the command button to submit the form, nothing happens.

@Rudi: I thought so (as I said, I'm new). What line could I add to do that? I have tried code with ".To = (recipient)" in it, but it doesn't seem to work either.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: command button issue

Post by Rudi »

Is it possible to upload your form? (Desensitized if necessary)
It will be a lot easier to assist you with the code if we can see it and know the setup of the form...

TX
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

metisbear
NewLounger
Posts: 7
Joined: 05 Jun 2014, 15:14

Re: command button issue

Post by metisbear »

I don't think I can upload a form here but I can email it to you to have a look.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: command button issue

Post by Rudi »

Welcome to....
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: command button issue

Post by Rudi »

TX... Got the form.

There is no prompt on the form for a user to enter an email address. Is the email address a fixed address to a specific mailbox. In other words, can it be hard coded into the macro?
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: command button issue

Post by Rudi »

Just a BTW:
If you go into the Full Editor option you will find an area where you can upload attachments.
See the screenshot attached...
1.jpg
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

metisbear
NewLounger
Posts: 7
Joined: 05 Jun 2014, 15:14

Re: command button issue

Post by metisbear »

Oh ok, thanks for the tip!

Yes, the email address is fixed. It's a specific shared mailbox.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: command button issue

Post by Rudi »

I'll set up an example and send the form back.
You can then update the sample email address with the appropriate one...
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: command button issue

Post by Rudi »

Hi,

I have sent the form back by email...
Give it a go and see if it does what you need.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

metisbear
NewLounger
Posts: 7
Joined: 05 Jun 2014, 15:14

Re: command button issue

Post by metisbear »

I tried it and I got an error. I've attached the screenshot.

Newbie question...do I delete the lines in green?
You do not have the required permissions to view the files attached to this post.

User avatar
Claude
cheese lizard
Posts: 6241
Joined: 16 Jan 2010, 00:14
Location: Sydney Australia

Re: command button issue

Post by Claude »

metisbear wrote:Newbie question...do I delete the lines in green?
Welcome to Eileen's Lounge.

The lines in green are comment lines, I'd leave them in there.
Cheers, Claude.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: command button issue

Post by Rudi »

metisbear wrote:I tried it and I got an error. I've attached the screenshot.
Newbie question...do I delete the lines in green?
Hi metisbear,

As Claude says, those green lines are comments that allow one to document the code and lines and provide explanations. They do not influence the code at all, so whether you keep them there or remove them will not make a difference to the functionality for the code.

As for the error; you need to set a reference to the Microsoft Outlook 14.0 Object Library.
To do this:
1. Open the VBA window
2. Click on the TOOLS menus and choose References
3. In the dialog that pops up, scroll and tick the following libraries:
-- Microsoft Outlook 14.0 Object Library
-- Microsoft Office 14.0 Object Library

See my image (ignore the 15.0 value as i am currently using Office 2013)
1.jpg
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

metisbear
NewLounger
Posts: 7
Joined: 05 Jun 2014, 15:14

Re: command button issue

Post by metisbear »

It looks like they are already checked, though one says "MISSING" in front of it. Sorry for all the fuss, guys.
You do not have the required permissions to view the files attached to this post.

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: command button issue

Post by Rudi »

No fuss... :)

Which version of Outlook are you running on your PC? Your screenshot icon indicates you have Outlook 2010, but your list indicates you had Outlook 2013.

1. Remove the checkmark next to Outlook 15.0 Object Library, then...
2. Scroll down and verify if you have an entry for Outlook 14.0 Object Library (if you have it, put a checkmark next to that)
3. Click OK to confirm

Attempt to run the macro now...
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

metisbear
NewLounger
Posts: 7
Joined: 05 Jun 2014, 15:14

Re: command button issue

Post by metisbear »

I am running Outlook 2010.

I unselected Outlook 15.0 Object Library and selected Outlook 14.0 Object Library and I clicked OK. When I did that, I got the message: "Error in loading DLL"

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: command button issue

Post by Rudi »

Hi metisbear,

It seems like there is some form of corruption going on. There should not be 2 versions of Outlook on your system and this might be the remnants of a previous install and uninstall. You may need to re-register the apps so that it restores registry settings of the programs.

Please note that I am unexperienced in this area, so I would recommend that before you heed my advice, please create a system restore point so if anything does go haywire, you can run system recovery to revert. My advice is probably not at all harmful, but I like to be safe :)

First step I'd suggest is to run a repair on your Office installation. Follow this process:
Access the Repair option from your Windows Control Panel -> (Add/Remove) Programs -> Microsoft Office -> Change installation -> Repair.
1.jpg
Try running the macro again now....

If this did not work try the following, though I think the fisrt step actually covers this anyhow (i'm just trying to cover all bases):

From the run command [WIN]+R, type this and enter: "C:\Program Files\Microsoft Office\Office\winword.exe" /unregserver Note: The quotes are necessary, but if it does not like the command, check the path and correct.
Immediately after this, reregister Word using: "C:\Program Files\Microsoft Office\Office\winword.exe" /regserver
I could not verify from Google, but even try it with outlook.exe (using same process as described)

After unregistering and reregistering, try again to run the macro...

Any success?
Holding thumbs!
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.