I'm trying to make an action button in Access to build an email with specific text, a few variables, and multiple lines that looks like this once in Outlook:
The brackets in the picture indicate the variables. I've tried a multitude of line codes, but I still can't get the variables or the text to look right. Here's the code I'm trying:
Dim Msg As String
Msg = "Dear " & txt_OfficerName & ",<P>"
<br /> Msg = Msg & "While searching for videos regarding " & Me.txt_CaseReportNumber ", I found that you had responded to the call, but your video was not tagged with the offense type and/or the CRN."
Msg = Msg & "It is important to remember that no matter your involvement in a call, if you respond on a scene, your video is considered evidence and must be held as such."
Msg = Msg & "You are required by policy to enter the appropriate offense in the Classify Tag and the 8-digit (no KC or dash [-]) CRN in the Case File Number field."
Msg = Msg & "Not doing so creates a risk of destroying evidence which may affect future court cases."
vbCrLf Msg = Msg & "Thank you,"
vbCrLf Msg = Msg & "<strong>Digital Technology Section</strong>"
vbCrLf Msg = Msg & "Note: This is an automated message that was produced based on findings made by DTS while searching for videos in response to a prosecutor/attorney request, court order, or other citizen request."
It depends what poperty you are going to set in the Outlook object model. The plain text message body (see the Body property) doesn't require any additional symbols, you can use standard constants, there are three different (constants) to add a line break.
bNewLine
vbCrLf
vbLf
But if you need to format the message body your choice is the HTMLBody property which requires a properly formatted HTML document. Here you can use any standard HTML tags like <p> and etc. See https://www.w3schools.com/html/ for possible options and tags.
Related
I use email to send my emails out. In body clause i use this code below. In bodyText variable i insert text comming from stringbuilder. However at the end when my email is received all text are not line b line but in one line. What am i doing wrong?
Mail.Body = "<HTML><HEAD></head><BODY style='font-size: 11px; font-family: Tahoma'>" + "<P>" & "Hi there," & ",</p>" + "<p>" & bodyText & "</p>" & "<p>This e-mail is generated automatically therefore <b>do not reply to this email.</b></p>" + "<p>Developer, </p>" & "Development team" & "</BODY></HTML>"
Stringbuilder:
_strbuild.Append("Start" + Environment.NewLine).AppendLine()
_strbuild.Append("Start" + Environment.NewLine).AppendLine()
You create some HTML so you have to use the HTML new line (<br>):
_strbuild.Append("Start" + "<br>")
_strbuild.Append("Start" + "<br>")
Instead of using the system new line (\r\n or \n) you have to use the <br> element. In HTML you can use the system new line only to format the HTML code not to format the output.
When the body of the message is sent in HTML format, add the (break - br) tags right in your String. vbCrLf and StringBuilder are not suggested as they don't work if the body is in HTML format.
Dim mail As New MailMessage
mail.IsBodyHtml = True
mail.Body = "Line one<br>"
mail.Body += "Line Two<br>"
mail.Body += "More Lines"
Environment.NewLine does not work because the current environment for your program is not the same environment where the user will read your result. Your environment is a console program (masquerading as a scheduled task or service), or web server application, or windows form, or something else where outputting a simple \n character results in a new line. The same applies to AppendLine(). It's using Environment.NewLine behind the scenes, and again, the problem is that your program environment is different than your user's environment.
In this case, your user's environment is an html document. HTML treats all simple whitespace the same, as a single space. This is true whether you have a tab, newline, space, or any multiples or combination of the above. It all consolidates to a single space in html.
So for html, in order to force a line break, you should instead include a <br> tag with your html. More than this, HTML will break up the lines automatically; you might get away without doing anything. Even in cases where you want an explicit line break what you're typically really doing from a semantic standpoint is asking for a new paragraph. This means <p> is commonly more appropriate:
_strbuild.Append("Start").Append("<p>")
If you really don't want the extra blank line from the new paragraph you can use styles to remove or reduce it (though admittedly e-mail is the one place where breaking the correct p vs br semantics might be appropriate: e-mail renderers can be difficult).
(Running on Win 8.1)
The ultimate goal is the answer to this question:
Using VBA in Outlook 2013, how can I examine incoming RSS posts for contained keywords?
The details so far:
As per this page: http://www.slipstick.com/outlook/rules/outlooks-rules-and-alerts-run-a-script/ (first paragraph after the initial quote), it is possible to have a VBA script in Outlook 2013 to process PostItem arguments.
RSS feeds provide a PostItem argument, as in
Public Sub ScanRSSPost(Item As Outlook.PostItem)
...
End Sub
However, the rules wizard won't show this procedure.
Other procedures processing mails coming in and having a MailItem argument as in
Sub AddMailToOPQueue(oMail As Outlook.MailItem)
...
End Sub
are displayed as selectable scripts in the wizard and work as expected.
Is the lady simply wrong, or am I overlooking a setting of which I am not aware?
You cannot process incoming RSS items the way Application.NewMailEx lets you process new messages, but you can still use Items.ItemAdd event on the folder corresponding to a particular RSS feed.
I found that the claim in the quoted post simply does not work.
If you have the same question, here is a work-around:
(1) In Outlook, create a new rule: on receiving any feed (or the particular one you are interested in), forward it to your mail address (I created a dedicated one to keep things clean and uncluttered), and process no further rules.
(2) On the receiving mail address, create a new rule calling a script like this:
Sub AddMailToOPQueue(oMail As Outlook.MailItem)
...
End Sub
In the routine, the forwarded RSS posts' oMail.Body property will start with: blank, vbCrLf, blank, vbCrLf, "Feed: ", so to extract the feed in question, you can use something similar as:
If Left(sBody, 12) = " " & vbCrLf & " " & vbCrLf & "Feed: " Then
sFrom = Mid(sBody, 13)
sFrom = Left(sFrom, InStr(sFrom, vbCrLf) - 1)
'sFrom has the feed name now. The post's subject is in oMail.Subject.
...
End If
(3) In Outlook, create another rule for the addressee, on receiving items executing above script, which will be selectable in the wizard.
I have a form in Access 2016 with a textbox in which I need to have multiple, semi-colon delimited hyperlinks (which will be dynamically created). What I've decided to do is create a "hyperlink construction string" in VBA, then assign them to the value of the textbox. So, something like:
Me.Field.Value = {link: www.google.com : "Google"} & "; " & {link: www.yahoo.com : "Yahoo"}
...would result in this being in the text box:
Google; Yahoo
My problem is, I can't seem to figure out the syntax to create an individual link in the textbox without making the entire textbox a single hyperlink, which isn't gonna work.
I was working with a few solutions that I've found. I read that this would create the link in the way I need, but it just comes through as literal text with the pound signs:
"Google # www.google.com # Some Argument"
I also tried setting the textbox to rich text, then setting the value to include rich text code for a hyperlink... but that's not working:
"{\field{\*\fldinst HYPERLINK ""http://www.google.com/""}{\fldrslt http://www.google.com}}"
I also thought about designing a Query that will return the hyperlinks. But, I kind of wanted to make it a VBA thing, because I'll have more flexibility in how I create the value. Does anyone have any ideas?
Note: I understand that multiple values should be in a 1:M relational database. They are. But, the requirements of the task are to get all the M values for a 1 entity, then list them out in semi-colon, delimited fashion, which all serve as links to a Details table for the M entity.
Regular textboxes (text only) don't support this.
It is possible with Rich text textboxes. In contrast to the name, they actually use a subset of HTML, not RTF.
With ideas from here I got this working:
Private Sub cmdInsertHyperlinks_Click()
Dim url1 As String, url2 As String
url1 = "D:\tmp\test.jpg"
url2 = "D:\tmp\test space.txt"
Me.rText.Value = "<div>" & _
"file://" & url1 & "" & _
" other text between hyperlinks " & _
"file://" & url2 & "" & _
"</div>"
End Sub
Note: the linked thread says you must URL-encode the links (space to %20 etc), but at least for my simple test, that wasn't necessary.
Note 2: You can't have a different display text and link url, at least I didn't get that to work.
So I'm working on my A Level coursework and have hit a block that I can't seem to work out. Basically, I have a bit of code that sends an email using text from a text file as well as a bit of hard coded text, all put into one variable before being passed onto the subroutine for sending an email.
I'm using a stream reading for both the email subject and body (as they're each in separate text files) and, while they're working fine elsewhere in the program, they're not working here. Rather than putting the contents of the text file into the variable before it's used to send an email, they're just putting the name of the text file there.
Also, the name of the file does not appear anywhere in the text stored within
E.g. The body of the email that it sent had the hard coded message and then it just said 'AbsenceEmailBody' (name of the text file) rather than what was inside the text file itself
Here's the lines of code where the files are read and put into variables
Dim objReaderSubject As New System.IO.StringReader("AbsenceEmailSubject")
Dim objReaderBody As New System.IO.StringReader("AbsenceEmailBody")
Dim EmailBody As String
Dim EmailSubject As String
EmailBody = "Dear " & CadetDS.Tables("CADET").Rows(0).Item("CadetFirstName") & "," & vbNewLine & vbNewLine & "It has come to the staff's attention that you have attended only " & ProblemAttendances(i, 1, 0, 0, 0) & "% of sessions." & vbNewLine & objReaderBody.ReadToEnd
EmailSubject = objReaderSubject.ReadToEnd
I also check the files exist before any of this
If System.IO.File.Exists("AbsenceEmailSubject") = True And System.IO.File.Exists("AbsenceEmailBody") = True Then
I've looked around everywhere and can't seem to find an answer. Also, this is my first time ever asking a question on here (or anywhere online) so if you need any more information just ask
I've been globalizing an application and have been using Resx Manager to make my life easier. I ran into a multi-line string literal and it stumped me.
How would I handle the escape characters when making this string into a resource?
If Not RelayMessage(
"Are you sure you want to do the selected action?" & vbCrLf &
"A confirmation message will be sent to the user." & vbCrLf &
"Please ensure you want to perform this action before hitting accept.",
My.Resources.Confirmation, RelayMessageOptions.Confirm_YesNo) =
DialogResult.Yes
How would I make that string into a resource?
In the standard VS resource manager (is this the manager you're using?) you can enter a multi-line string resource directly in the editor by using shift-Enter:
Note that this is actually stored as a string with CR+LF pairs, assisted by the space="preserve" attribute. Viewing the .resx file in a text editor:
Results using a standard message box:
MessageBox.Show(strings.myString)
I don't know how it is usually handled in globalization problems. But an easy way would be to define your own escape character formats. For example you could define \n as a newline character. When you actually use your ressource you could then use
If Not RelayMessage(Strings.Replace(myResourceString, "\n", vbCrLf),
My.Resources.Confirmation, RelayMessageOptions.Confirm_YesNo) =
DialogResult.Yes
instead of
If Not RelayMessage(myResourceString,
My.Resources.Confirmation, RelayMessageOptions.Confirm_YesNo) =
DialogResult.Yes
Or you could manually add chars with character codes 10 and 13 (e.g. ChrW(10) & ChrW(13)) at the vbCrLf location in your ressource string. This equals a vbCrLf (meaning a carriage return (10) + line feed (13)). This would avoid manipulation of the source code. Other stuff like Tab (9) have codes, too. These are called control characters. Take a look at the wikipedia http://en.wikipedia.org/wiki/Control_character