Consulting

Results 1 to 4 of 4

Thread: Solved: Display e-mail message

  1. #1
    VBAX Regular
    Joined
    Nov 2005
    Posts
    14
    Location

    Solved: Display e-mail message

    Hello,

    I have this script in a form I am building
    [VBA]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[/VBA]

    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?

    Cheers,

    James

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    The code is fine in principle - except maybe you could declare the mail item variable[VBA]Dim msg as MailItem[/VBA]
    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.
    K :-)

  3. #3
    Yup, a modal userform will generate the aforementioned error.

  4. #4
    VBAX Regular
    Joined
    Nov 2005
    Posts
    14
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •