Home

Cardbox

 
Cardbox > Support > Knowledge Base ...

Message text in emails

 

The Cardbox help file gives various examples of macros that can be used to send emails from Cardbox databases. Some of the macros send a different message to each recipient, while others send an identical message to everyone. The identical-message sample macros all contain the commands

MessageText = "Here is a sample message sent from Cardbox." MessageText = MessageText & vbCrLf & "The message has two lines."

which mean that the emails will contain the following text:

Here is a sample message sent from Cardbox. The message has two lines.

This article describes how to replace the sample message with a real one that you might really want to send to your correspondents.

1. Constructing the message within the macro itself

The most direct method is to adapt the commands in the sample macro.

For the first line or paragraph of the message, use the command

MessageText = "xxxxxxxxxxxx"

where xxxxxxxxxxxxxx is the text that you want to put into the message. This text can be any length you like, from a single word to an entire paragraph, and the only rule is that when you type it into the macro, you have to type it all as one long line. (Also, if you have a quotation mark " in the text, replace it with two consecutive quotation marks "").

For each following line or paragraph, use the command

MessageText = MessageText & vbCrLf & "yyyyyyyyyyyyyy"

where yyyyyyyyyyyyyy is the text that you want to put into the message. The "MessageText &" is there so that the macro adds the new text to the end of the existing text, instead of replacing it. The "vbCrLf &" inserts a new-line marker to mark the end of one line (or paragraph) and the start of a new one.

If you want to have a blank line between lines or paragraphs, you need to say something like this:

MessageText = MessageText & vbCrLf & vbCrLf & "yyyyyyyyyyyyyy"

where the first vbCrLf ends the previous line or paragraph and the next vbCrLf creates a blank line.

Example

Dear Member, The next meeting will be held on Thursday 14 January at 2.30pm. Agendas will be distributed seven days before the meeting, and if you have not received your agenda by the 10th then you are asked to contact the Honorary Secretary. Yours sincerely Ethel Honywood Hon. Secretary

MessageText = "Dear Member," MessageText = MessageText & vbCrLf MessageText = MessageText & vbCrLf & "The next meeting will be held on Thursday 14 January at 2.30pm. Agendas will be distributed seven days before the meeting, and if you have not received your agenda by the 10th then you are asked to contact the Honorary Secretary." MessageText = MessageText & vbCrLf MessageText = MessageText & vbCrLf & "Yours sincerely" MessageText = MessageText & vbCrLf MessageText = MessageText & vbCrLf & "Ethel Honywood" MessageText = MessageText & vbCrLf & "Hon. Secretary"

2. Constructing the message within the macro (alternative version)

The VBScript language has a feature that allows a command to be continued from one line to the next. This is done by putting an underline character (_) at the end of the line to be continued. Here is the same example, done using this method:

MessageText = "Dear Member," _ & vbCrLf _ & vbCrLf & "The next meeting will be held on Thursday 14 January at 2.30pm. " _ & "Agendas will be distributed seven days before the meeting, " _ & "and if you have not received your agenda by the 10th then you are asked " _ & "to contact the Honorary Secretary." _ & vbCrLf _ & vbCrLf & "Yours sincerely" _ & vbCrLf _ & vbCrLf & "Ethel Honywood" _ & vbCrLf & "Hon. Secretary"

We've made one change, to make the macro more legible (it makes no difference at all to what the macro actually does). Rather than have the main paragraph as one long line stretching off to the right, we've split it into several shorter pieces. The reason that this change makes no difference is that we haven't put "& vbCrLf" at the beginning of the extra lines, so VBScript will splice them together into one long line (or paragraph) and not treat them as separate lines.

3. Getting the message from the Clipboard

If you don't want to modify the macro every time you want to send a different message, you can make it get the message text from the Clipboard. If you do this, then the procedure for sending a bulk email becomes:

  1. Select the records you want to send the email to.
  2. Create the email text in Wordpad or Notepad.
  3. Select it all and copy it to the Clipboard.
  4. Run the email macro.

The relevant MessageText statement in the macro is simply:

MessageText = ClipboardText

Using the Clipboard does run the risk of terrible accidents. Suppose that you are interrupted just after copying the text to the Clipboard, and that whatever you do when you handle the interruption involves copying and pasting something. When you come back to play the Cardbox macro, the Clipboard no longer contains the text of your email. This could be very embarrassing, as you send hundreds of people an email containing a single word, or a piece of a letter you were writing to someone else, or whatever else happens to be lying around the Clipboard at the time.

For safety, it may be better to do this:

MessageText = ClipboardText If MsgBox("Please check the email text:" & vbCrLf & MessageText,vbOKCancel,"Email Sender")<>vbOK Then Halt

This displays the text of the message it is about to send and asks for confirmation that it is the correct one. If you click on Cancel then the macro halts and nothing is sent.

3. Getting the message from a file

Finally, you could compose the entire message in a Notepad file (filetype .txt) and get the Cardbox macro to ask you for the filename. Here are the macro commands that you would use:

InputFilename=GetOpenFilename("Emails|*.txt") If InputFilename="" Then Halt MessageBox=CreateObject("Scripting.FileSystemObject").OpenTextFile(InputFilename).ReadAll If MsgBox("Please check the email text:" & vbCrLf & MessageText,vbOKCancel,"Email Sender")<>vbOK Then Halt

As with the Clipboard example, we have made the macro display the message text to confirm that you have chosen the right message.

© 2016 Martin Kochanski
"Cardbox" is a registered trademark.
 Top of page