PDA

View Full Version : Solved: Display e-mail message



Sissyfoo
11-20-2005, 05:20 PM
Hello,

I have this script in a form I am building
Sub cmdCreate_Click()

Dim MsgSubject As String

MsgSubject = txtSubject.Text

Set msg = Application.CreateItem(0)
msg.Subject = MsgSubject
msg.Body = "what you want to say in the body of the message"
msg.display

End Sub

but for some reason I cannot get the e-mail message to display on screen. I usually get a message saying that there is a dialog window still open.
If I take out the msg.display line then nothing happens at all when I press the button.

Is there a way around this or, to be more specific, what the hell am I doing wrong? http://vbaexpress.com/forum/images/smilies/102.gif

Cheers,

James

Killian
11-21-2005, 08:09 AM
The code is fine in principle - except maybe you could declare the mail item variableDim msg as MailItem
But reading between the lines... well the first line actually, the procedure name "cmdCreate_Click" makes me suspect this is the event code on a user form commandbutton.
If the UserForm is modal (ShowModal property is True) then it won't allow Outlook to have the focus (and show a mailitem) until it's closed. If you have OL2000+, you can have non-modal forms, otherwise, you'll have to change the program flow so you call msg.Display from a standard module.

chocobochick
11-21-2005, 08:20 AM
Yup, a modal userform will generate the aforementioned error.

Sissyfoo
11-21-2005, 03:29 PM
Modal and non-modal, eh? You learn something new everyday! Had to do a bit of searching to find out what it all meant but I found it and my problems (so far this morning) are solved! Huzzah!

Thanks very much. :)