PDA

View Full Version : CONTROLLING INTERFACE APPEARANCE



timetunnel
02-23-2007, 10:43 AM
Hello everyone:

Since I made the mistake of setting up a humble document management system at work, I now find myself doing more of the same. Color me masochistic.

I'm currently working on an extremely simple system to email various Word "boilerplate" documents to select groups of folks via option buttons on a menu, which is really a simple, but pretty large userform. This part is cake.

However, what I really don't like is that once the menu option is selected and the code starts working, the menu goes away and you never know what will be in the background. Might be the desk top or might be Outlook depending on what the user was doing previoulsy. This can look rather confusing, since I have to display an inputbox for the user to key some event specific info into, that is added to the boilerplate in the doc that is being emailed.

What I'd like to come up with is a blank screen that would be displayed as a background while my code executes and then goes away. I don't want to leave the menu up because I don't want to increase the possibility of the user selecting a undesired menu option. I plan to put a little "hook" in the code which will provide an escape route should they select the wrong customer menu option.

I have this system setup so that the user never actually sees the boilerplate document and once they key the extra verbeage into the inputbox, the "application" closes and the doc is emailed.

SO, anyone have a good suggestion for handling this?

Regards to all!

fumei
02-23-2007, 11:00 AM
However, what I really don't like is that once the menu option is selected and the code starts working, the menu goes away and you never know what will be in the background. Huh?????

Sorry, but you are going to have to describe this better.

WHAT menu, and WHERE is it? You say a userform...OK, what application is running in order to display the userform? The code started by - I assume a commandbutton, although you do not say so.... - may close the userform (although it does not have to), but it should not close the application used to call it.

Not unless you made Application.Visible = False. Which you do not say.

You mention "userform", you mention "inputbox", you mention "menu"

I am not sure, but it almost seems you are using these interchangeably.

Care to actually REALLY describe what you are doing?

timetunnel
02-23-2007, 12:10 PM
The meuu - which is a userform with option buttions is a Word template.

Well lets see, how much of this did I actually describe:

From my post:

"via option buttons on a menu, which is really a simple, but pretty large userform." I believe I described what I meant by menu.

Then I attempted to explain my additional objectives via this sentence:

"What I'd like to come up with is a blank screen that would be displayed as a background while my code executes and then goes away. I don't want to leave the menu up because I don't want to increase the possibility of the user selecting a undesired menu option."

Menu was defined earlier. It is in fact a Word Userform. What I'd like to have happen is once a menu option (WORD userform option button) is selected, the menu (Word userform) would close and a blank background would appear and remain while my code executes and then disappear after my code finishes.

Sorry if my grammer presented issues.

timetunnel
02-24-2007, 09:27 AM
MORE ON THIS POST:

I guess I've done a rather poor job of communicating in this post and generally communication is my strong suit. Well, that's what happens when you get old and attempt to hang in there with technology. So I appologize to everyone (ESPECIALLY FUMEI) for being an old toad. :omg2:

I should have mentioned that I'm using:
With Application.ActiveDocument.MailEnvelope to send the doc as email.

The trouble seems to be that, if I'm not out of Word when Outlook attempts to send the email via this mechanism, it will sit and wait until I get out of Word and reply to a dialog box that is generated when Outlook goes to work via this method. The dialog box says something like "Outlook is attempting to send a email in your behalf..." and it requires a reply before the email goes on it's way.

The thing I don't like about this is that this dialog box is just "floating" somewhere over the users desktop and I'd like it to show up over the Userform (my psuedo menu) where the option (command button or option button) was taken to send that particular doc as email. Or better still, over a "blank screen", which I suppose could be a blank doc, if the email would still be sent under this scenario.

There are some other things about this method that are a bit troublesome and I've had to do some error handling, but the method definitely works just fine in terms of actually sending the email.

I hope I haven't confused anyone beyond redemption and that someone will reply! :sad2:

Regards...

lucas
02-24-2007, 09:53 AM
Check this out Timetunnel

http://www.vbaexpress.com/forum/showthread.php?t=7847

timetunnel
02-24-2007, 10:10 AM
Thanks Lucas.

I've printed it off and am going to brew some coffee and read and try to digest it.

I really appreciate you taking time to help

Regards,

fumei
02-24-2007, 10:51 AM
You did NOT mention it was a Word userform. You did NOT mention it was fired by a template. In fact, I still do not know how the userform is displayed.

Look, I will try and read your mind....

1. You use File > Open (IN Word, so Word IS open) to clone a template.

2. The template Document_New event fires.

3. The userform is displayed.

4. User does stuff on the userform, and presses a commandbutton which starts to execute some code.

First of all, the userform will not "go away" unless you have instructed it to do so.

Second of all, if you have instructed it to do so, you should have Word on screen - not the desktop or anything else. Not unless, as I mentioned, you have made Word invisible.

BTW: age has nothing to do with it. I am pretty old myself. It is simply trying to describe things accurately.

Now, it is true that if the instruction from that commandbutton is sending an email you DO indeed have an issue of that Outlook security warning.

You mention that the user never sees the document. That implies that you DO have Word invisible.

Sorry if I sound grouchy. My apologies. All I want to know is exactly what you are doing.

This sounds like a focus issue.

lucas
02-24-2007, 11:01 AM
BTW: age has nothing to do with it. I am pretty old myself.
me too.
Hi Gerry....what I get from timetunnel is that the word document is still visable after submission but the outlook securtity dialog is hidden behind word and they have to close or minimize word to deal with the security dialog....I'm guessing here too. Maybe it will become clear in their next post.

timetunnel
02-25-2007, 03:14 PM
Hey Gerry, it's OK to be grouchy. I think I made it pretty easy:what:

Steve has pretty much hit it on the head, but I want to elaborate further:

I have a WORD template. It's ONLY function is to display a userform which will contain lots of command buttons (or options buttons) and will be the front-end "menu" for this system. Each button will of course have some code. The ultimate result of selecting a menu option will be sending a specific email via Outlook utilizing the: Application.ActiveDocument.MailEnvelope method. The method enables passing parameters to the target Outlook email such as: Subject, Recipients, BCC, Introduction and etc.

Each of my "menu options" (userform buttons) will fire code to open a unique WORD document, and display an inputbox with a prompt asking for some specific information. This specific information depends on the scenario that prompted the user to select a particular menu option. Usually this requested information is simply the time when a certain event (that relates to the "topic" of the menu option) occured.

Whatever is keyed into this inputbox will be passed as an "introduction" into the email that I'm going to generate via the: Application.ActiveDocument.MailEnvelope method.

The document that I opened when the "menu option" was taken will become the body of the email message. Not an attachment, but the actual body of the email.

The recipients of this email will be determined based on a relevant distribution list, which will be maintained in Outlook. The name of this distribution list will be passed into the BCC (blind carbon copy)field of the email being created , again via the: Application.ActiveDocument.MailEnvelope method.

Here's an idea of how the code for the method looks:

FIRST I OPEN MY "BOILERPLATE WORD DOCUMENT" AND PROMPT THE USER FOR THE INTRODUCTORY INFO:
CODE BLAH, BLAH, BLAH

Then I tie it together and execute the method:

With Application.ActiveDocument.MailEnvelope
'Add some introductory text before the body of the e-mail.
.Introduction = "info from inputbox!"
'Return a Microsoft Outlook MailItem object that
'you can use to send the document.
With .Item
.BCC = "name of my distribution list goes here"
.Subject = "WHATEVER goes here"
'The body of this message will be
'the content of the active document.
.Send
End With
End With

This will pass the body of my open document into the body of the email and fire it off.

This by the way all works fine.

My constraints at this juncture are: I don't want the user to mess with the Word doc that becomes the body of the email. In fact they don't really have to see it. So I think that closing it is probably OK.

After the method executes, you have to get out of Word so you can, as Steve said, deal with the security dialog. The email isn't actually sent until this happens!

What I don't want is for the user to have to alt-tab or hunt all over the place to find the security dialog box. It would be really neat if there were a way to have this dialog appear over the " main menu" (WORD template - userform), but I can't figure this out. So what I do now is close everything (WORD doc that is the body of email and the WORD template with userform that is the "meun") and exit WORD so the security dialog from Outlook is visible.

Let me apologize to everyone for the ambiguity in my previous posts on this subject. I retired nearly 4 years ago and only went back to work within the past 2 1/2 months. The last 10 years of my previous IT career were spent in senior management positions and I haven't messed with anything resembling code in a very long time. For the past 3 1/2 years I've been doing wood boat restoration and playing golf, so my IT thinking cap isn't worth much at all!

Thanks to all...

fumei
02-26-2007, 07:08 AM
No, no, this is OK. I just wanted a clear and consise description of what was happening. Which you have now done.

OK. First of all, why are you using an inputbox? Why not have a textbox on the userform to get this information?

However, that is a minor point.

OK, so it IS a focus issue. The Word userform executes some code, which fires the security warning dialog in Outlook.

What I am not quite understanding is if you close the Word userform, and Word, how is the code still executing? It may be trying to pass focus to Outlook, but closing Word should (I think) terminate the code execution.

Have you tried making Word Visible = False.

OR, are you creating an instance of Outlook? Is Outlook already open? If it is, Outlook is a single instance application. You could try having an Outlook instance (a new, or existing) as part of your Word userform code. Then you may be able to hide Word, and explicitly make Outlook visible, and therefore have focus.

timetunnel
02-26-2007, 11:14 AM
Gerry:
This is great! You've hit on something that I didn't even know about. But, let me answer your questions.

Question: OK. First of all, why are you using an inputbox? Why not have a textbox on the userform to get this information?

Answer: My goal is to make the userform appear to be nothing more than a page of menu options. So it's comprised of commandbuttons and each button's caption describes a different email scenario. For example, option button 1 caption = Send notice to XYZ customer. Button 2 = Send notice to QA2 customer, and so on. I have to minimize confusion for the users and so I've elected to make the interface very, very simple.

The code behind every button is essential identical. The only difference is that the Word document that is opened with each command button (and ultimately becomes the body of an email) is just a little different. And each email message requires a little bit of "added text", unique to some event that has occured, which actually created the need to send the email. The other difference is that each email being created is sent via a different distribution list.

Thus I open an inputbox in the code behind each optionbutton and this is the first thing the user sees. So the user keys in the extra info into the imputbox and this gets passed into the email body via the ".introduction" parameter shown in the code in my previous thread. So the user closes the inputbox and the code continues.

Once the code hits the .send line (please see previous thread) - the email goes and my work is complete. Its then that I close everything out.

As you state, it certainly has to be shifting the focus to Outllook. And since I didn't even know I could control that by adding an Outlook instance, I've just been ensuring that Outlook is running before I run the code. A sloppy solution at best and this explains my inability to "make it pretty" for the users!
And I think you've just solved my entire problem! :super:

I'll start experimenting with adding an Outlook instance when I get to work. Unfortunately, my home version of Office is so old that a lot of the functions don't work and I have to run everything at work. The other big problem is that, due to the nature of our business, I'm not permitted to access this forum from work!!! What a hassle!

Thanks a ton Gerry!

fumei
02-26-2007, 11:45 AM
Just remember that Outlook IS a single instance application. So even using CreateObject will use the current session, if one is running. Howver, by explicitly having an Outlook application object you should (I hope) fix this by passing focus explicitly TO it, at the right time.

Let us know.

timetunnel
02-27-2007, 10:00 AM
Thanks again Gerry:

After more experimentation I see there is still work to do.

I am getting the email to go and that's the biggest deal. However, there is still some weirdness in the code. I've tried many variations and the .Send (which actually mediates to Outlook and launches the email) will not work unless I do some error handling.

I have managed to get the security dialog box to appear without having to hunt around for it, but I've had to minimize my Word files for that to happen.

Although I've hidden userforms, I've never tried to actually hide Word and that may be the missing link. I'll have to figure out how to accomplish this when I get to work and get a little free time. Work and free time an oxymoron for sure...

Regards and thanks again!

lucas
02-27-2007, 10:08 AM
I have managed to get the security dialog box to appear without having to hunt around for it!

Why not get rid of it altogether....see post #5 of this thread...when you get to the link look specifically at post #7

fumei
02-27-2007, 10:39 PM
Except is he not running this from Word? If I understand correctly, the post (#7) specifically states the code is being run from Outlook.

timetunnel
02-28-2007, 10:45 AM
Hi again!

I am in fact running this whole thing from Word. The method:
"With Application.ActiveDocument.MailEnvelope" has a ".Send" that causes Outlook to get involved and send an email consisting of my Word boilerplate verbage.

This method seems to be a bit sketchy in that I have to do some error handling in order to get it to work at all, but it does ultimately get it done.

And it seems that the only option I have for displaying the Outlook security message is to minimize my Word template (menu - uesrform) and doc (boilerplate). I can't close either, since the template is running the code and the doc has to be open for Outlook to mediate the email. And if I don't minimize them, everything just "sits" until I go to where the Outlook security message is and answer it. This is not a great thing considering those who will be using it are not - let's say, very "handy".

The fact that the security message appears is not that bad. I just wish I could leave my template (menu) maximized and just have the message display over it, but this won't happen. So I haven't found any way, other than minimizing the Word template and doc to have the security message visible without alt-tabbing all over the place.

One thing I should mention is that Outlook will always already be open when this system is used. So I can't really control an instance of it from my code. If I could, perhaps none of this would be an issue???

This probably seems like a lot of messing around to get an email launched, but if this works as I envision, it would seem like a really big deal to the folks who would be using it and maybe they'll think I'm cool and bring in some homemade brownies or fudge!!!

It is rather disturbing that there seems to be a lot of instability in the method that evokes Outlook! And maybe that's just my ineptitude.

Regards

fumei
02-28-2007, 05:06 PM
One thing I should mention is that Outlook will always already be open when this system is used. So I can't really control an instance of it from my code. If I could, perhaps none of this would be an issue???I don't think this is accurate.

You can still make an Outlook instance, an object, from Word. It simply will use the currently running one. Nevertheless, the object created in Word should be useable. Which means it shoud be callable, which means you should be able to give it focus. Which should alleviate the minimizing of Word...I think.

However, as the code is still being run from Word, you will likely get the security message.

I can not seriously try to duplicate this from where I am, but when I get a chance I will give it a go.

timetunnel
03-01-2007, 09:29 AM
Hi Gerry
Well, I'm afraid that's beyond my current experience. If you should get a chance to put something together on this, I'd love to check it out.
There seems to be some unpredictability in what I'm doing. Every time I execute this, I have already opened Outlook (via Windows not code).
The last time I ran the code, Outlook actually closed out and I'm not "intentionally" doing anything to make that happen and it doesn't happen every time! The email was still sent and I received it once I reopened Outlook, but it's just sketchy. And sketchy isn't going to work in this scenario!
I think I'll post my code here for everyone to see. That's probably going to end up becoming embarrassing, but I really want to learn how to do this right. As elementary as this whole thing seems, the application of this is really quite valuable.
Thanks for hangin' in there with me on this!