Calling a dialog form with HTML control that returns OK/Cancel

morsagmon

Registered User.
Local time
Today, 06:20
Joined
Apr 9, 2010
Messages
35
Hello.

I have a module in which I construct a STRING holding an email body in HTML format (contains HTML tags, such as <BR> and nbsp's).
Before I send out the email I'd like to present to user with the email content as it will arrive for approval, and based on his choice (OK or Cancel) - stop or proceed with the module execution.

I can't use msgbox or inputbox, as they don't support HTML (and also limited to 1024 chars).
The best idea that comes to mind is calling a FORM (with Rich Text control to accommodate for the HTML message) that has two buttons: "OK" and "CANCEL". Something like this:
intChoice = OpenForm("myForm", args...)
The problem: I don't know how to call a regular FORM from VBA that RETURNS a parameter just like a function does so that I can capture the OK/Cancel action.

Any ideas what's the best strategy here?
Thanks!
 
In your module, you might have code like this:
Code:
[COLOR="Navy"]Option Explicit

Public[/COLOR] frmCode [COLOR="navy"]As String

Public Function[/COLOR] frmCodeGet() [COLOR="navy"]As String[/COLOR]

    DoCmd.OpenForm "MyForm", , , , , acDialog
    frmCodeGet = frmCode

[COLOR="navy"]End Function[/COLOR]

In the form MyForm, you might have two buttons, cmdOK and cmdCancel, and your form's code might look like this:
Code:
[COLOR="navy"]Option Explicit

Private Sub[/COLOR] cmdCancel_Click()
    frmCode = "Cancel"
    DoCmd.Close acForm, Me.Name
[COLOR="navy"]End Sub

Private Sub[/COLOR] cmdOK_Click()
    frmCode = "OK"
    DoCmd.Close acForm, Me.Name
[COLOR="navy"]End Sub[/COLOR]
 
Hello.

I have a module in which I construct a STRING holding an email body in HTML format (contains HTML tags, such as <BR> and nbsp's).
Before I send out the email I'd like to present to user with the email content as it will arrive for approval, and based on his choice (OK or Cancel) - stop or proceed with the module execution.

I understand fully what you want to do. It is an easy way and simple but it is a little bit "old" and redundant. You want to make a form to show email content, so that a user can decide to send it or not. This is exactly what an Email is. Outlook is just a series of forms. The form named email is the one that we use all the time. We fill out a couple of fields and then hit the send button. It sounds like you want to reproduce this.

Thus why not just show the user with olEmailItem.display the fully completed email and let them send it? This would be the same as clicking OK.

If you are worried about them sending it, you can track and check to make sure they have sent it. by using some Public WithEvents hooks into the email.

You could even go one step further and create your own email form in outlook. see Tools>Forms>Design Form - then choose email. You could alter the standard email form to your own kind eg. Body text not editable and save your own special form. (please note I know this bit in theory only I am currently exploring the possibilities here myself)
 
ByteMyzer,
Thanks for your idea - I'll give it a try.

darbid,
I'm fully with you on this, and I don't have any issue with the user hitting the "send" button.
I'm not using Outlook, though. I'm sending this email through a Gmail account using smtp (see here an example, only I had to change port to 465 and add ssl = true for it to work with Gmail).

Thanks!
 
Bdarbid,
I'm fully with you on this, and I don't have any issue with the user hitting the "send" button.
I'm not using Outlook, though. I'm sending this email through a Gmail account using smtp (see here an example, only I had to change port to 465 and add ssl = true for it to work with Gmail).

Thanks!

Thats good, but you have to then decide what your email client will be. If you want to use Google then you will have to try and use google forms (which i assume do not exist) If you use Outlook as the client then you get the benefit of all the forms and all the other stuff that outlook comes with.

I am sorry but without Outlook unless your choice of email client offers forms and they also offer an API or COM compliant link to VBA (ie so you can control it from VBA) then your original idea is the best.
 

Users who are viewing this thread

Back
Top Bottom