VBA Code to change font and size in an email from access - vba

I have an access form that runs a query. There is a command button on the form that I want to send an email with the query results attached in an excel spreadsheet. Using the code below I am able to attach the results and send the email ok. I would like to be able to format the email body so that it is more noticeable. I'm not really sure how to go about doing this and still have my query attached. I have also created an email template that I would use but I haven't been able to figure out how to use the template and attach the query results. I'm open for any suggestions. Any help would be greatly appreciated.
DoCmd.SendObject acQuery, "BoxOrder", "ExcelWorkbook(*.xlsx)", "me#home.com", _
"John#hishome.com", "", "BOX ORDER", _
"ALL BOXES STITCHED" & vbCrLf & "Questions: Please Call Me" & _
vbCrLf & "555-555-5555 x 66654", True, True

You could follow the Article from MS.
A proportion of the code is as follows:
Set ola1 = New Outlook.Application
Set mai1 = ola1.CreateItem(olMailItem)
mai1.To = strTo
mai1.Subject = strSubj
If bolHTML = True Then
mai1.HTMLBody = strBody
Else
mai1.Body = strBody
End If
mai1.Display
If you use the HTML (set bolHTML = True) version you can either have an RTF control on a Form and pass the formatted text over or hardcode your HTML with the formatting you need. Just set the "strBody" to the message you want.
Then you need to look into the Attachments.Add (MS Article) if you want to use the above code with your original purpose.
There's a full 599CD Email Seminar you could follow if you're going to be doing a lot with Email in Access.

Related

Add embedded hyperlink to MS Access textbox in form

I try to do the embed a hyperlink in a textbox (rich text) in a MS Access form . Would this be possible? Didn't found any solution in the web so far...
Something like:
Me.TextWithLink = "Text here for link <b> Hyperlink Text</b>"
PS: Textbox is set to RichText, tried to set to hyperlink true/false but not working...
Is there any workaround?
Form_Formular1.Text0.Value = "your text http://www.google.de"
Would produce automatically
As well as
Form_Formular1.Text0.Value = "your text http://www.google.de"
but obviously the URL and the hyperlink text needs to be the same. So
Form_Formular1.Text0.Value = "your text " & url & ""

Receiving "Run-time error '2293': Microsoft Access can't send this e-mail message" after having no issues

I have a button on an Access form that queues up an email and is linked to several fields on the form. Yesterday and this morning the button was working without issue. I have not changed the underlying code or any of the fields in the form, but suddenly the button is returning a Run-time error '2293': Microsoft Access can't send this e-mail message error message when I click it. An example of the code is as follows:
Private Sub cmd_Button_Click()
Dim toaddress As String
Dim ccaddress As String
Dim subject As String
Dim message As String
toaddress = AddMailAddress(toaddress, Nz(Me.cmb_ProjectLead.Column(1), ""))
toaddress = AddMailAddress(toaddress, Nz(Me.cmb_ProjectLead2.Column(1), ""))
ccaddress = AddMailAddress(ccaddress, Nz(Me.cmb_OtherPOC.Column(1), ""))
ccaddress = AddMailAddress(ccaddress, Nz(Me.cmb_OtherPOC2.Column(1), ""))
subject = "text" & me.txb_ProjectName
message = "text" & me.txb_ProjectName & vbnewline & me.txb_ProjectLocation & vbnewline & me.txb_ProjectDescription
DoCmd.SendObject acSendNoObject, , , toaddress, ccaddress, , subject, message, True
End Sub
When I click "debug" on the error message, the line DoCmd.SendObject acSendNoObject, , , toaddress, ccaddress, , subject, message, True is highlighted yellow with a yellow arrow pointed to it.
A few notes that may be helpful:
I'm working on a work issued computer and I have no Admin rights, so changing certain properties are not possible.
I have to use a VPN which has pretty strict security standards.
To reiterate, this worked up until today. In fact for the same record, it worked one moment, and then 30 seconds later did not work.
*Update: the command worked when I stripped everything except the sendobject line and replaced the values with text, i.e.
Private Sub cmd_Button_Click()
DoCmd.SendObject acSendNoObject, , , "toaddress", "ccaddress", , "subject", "message", True
End Sub
When I added just the toaddress and ccaddress back in, I got the 2293 error message.
*Additional info that may help: This form has several "Email To" buttons as well as some "Send Outlook Apppointment To" buttons. They all also worked fine up until this morning, but are now generating various error messages when clicked. They all use the same toaddress, ccaddress, subject, message, etc format as my example here.
The public function that is also linked to these commands is as follows:
Public Function AddMailAddress(address As String, newaddress As String)
If (address = "") And (newaddress = "") Then
Exit Function
End If
If address = "" Then
address = newaddress
Else
If Not newaddress = "" Then
If VBA.Right(address, 1) = ";" Then
address = address & newaddress
Else
address = address & ";" & newaddress
End If
End If
End If
AddMailAddress = address
End Function
Anytime i get this error, it has nothing to do with the the database or the code, it is simply due to the fact that i have an outlook item open that is currently gettin edited that i have forgotten about.
Access cannot create a new Outlook item while there is currently an Outlook item open in edit mode.
Close down any Outlook items open in edit mode and try again.
The email buttons now work after closing out the database and re-opening it. Still no clue why it gave me run-time errors before. If it happens again, I'll be back to add more insight.

Finding attachments with dav queries using AdvancedSearchMethod

I'm attempting to use the advanced search method to filter through large numbers of emails. I am looking at ultimately creating a filter like:
filter = "(urn:schemas:mailheader:subject like '%project%' or " _
& "urn:schemas:httpmail:textdescription like '%project%') and " _
& "urn:schemas:mailheader:date > 'now - 1:00:00' and " _
& "urn:schemas:httpmail:hasattachment > 0 and " _
**& "urn:schemas:httpmail:attachmentfilename like '%tonnage%'"**
The problem is that the part for the attachment's filename (line in bold) does not work. I believe this is because it is looking for something like the olmailitem and not the attachment to that object perhaps. Anyway, I need to get a simple filter that looks at attachments working and then I can scale it up. This is what I have so far:
scope = "'Fakeexample123#outlook.com'"
'this is a dumbed down version of my filter,
'but I want it to search for 3 instances of '%attachment%':
'attachment
'Attachment
'ATTACHMENT
'for any .xls, .xlsm, or .xlsx files
'I was thinking something like:
'filter = "ucase(urn:schemas:httpmail:attachmentfilename) like '%ATTACHMENT%xls%'"
'but I don't believe that works... ideas?
filter = "urn:schemas:httpmail:hasattachment > 0 and " _
'***************** This is the line that is giving me trouble *****************
"urn:schemas:httpmail:attachmentfilename like '%attachment%xls%'"
'***************** End trouble *****************
Set AdvancedSearch = myOlApp.AdvancedSearch(scope, filter, True, "test")
Let me know if you have any thoughts please.
You need to find items with attachments first, for example, you can use the following condition:
"urn:schemas:httpmail:hasattachment" = 1
Note, a SQL syntax should be used to get it working correctly in Outlook.
filter = "#SQL=""urn:schemas:httpmail:hasattachment"" = 1"

Add hyperlink into Word Content Control with VBA

I have a Word 2010 template. When used, a form is presented to the user and they are prompted to enter a string in a textbox named BugNumTextBox. Upon command, I wish to construct a URL, create a hyperlink, and insert that into the document.
The desired insertion point (anchor) is a Rich Text Content Control with a tag name of "foo".
For the address parameter I have attempted:
1) To specify the range of the content control
2) To specify the range of a bookmark (named BugNum) that I created inside of the content control.
Neither have worked, resulting in run-time errors.
Can anyone suggest a method to achieve this?
Below is a non-working example of method 2 above.
ActiveDocument.Hyperlinks.Add Anchor:=.Bookmark("BugNum").Range, Address:= _
"http://bugs.fubar.net/show_bug.cgi?id=" & BugNumTextBox, _
SubAddress:="", ScreenTip:="", TextToDisplay:=""
Thank you much.
Why don't you access the ContentControls Object Collection instead.
Something like:
Dim ccRtxt As ContentControl
Set ccRtxt = ActiveDocument.ContentControls(1)
ccRtxt.Range.Hyperlinks.Add ccRtxt.Range, _
"http://stackoverflow.com/questions/26538906/" & _
"add-hyperlink-into-word-content-control-with-vba"
Above will work on the scenario you describe where you only have 1 ContentControl.
If you have many such objects, you can do this:
Dim ccRtxt As ContentControl
For Each ccRtxt In ActiveDocument.ContentControls
If ccRtxt.Tag = "foo" Then
ccRtxt.Range.Hyperlinks.Add ccRtxt.Range, _
"http://stackoverflow.com/questions/26538906/" & _
"add-hyperlink-into-word-content-control-with-vba"
End If
Next
This adds this question as hyperlink address in your Rich Text Content Control.
You can adjust the address property to suit your needs. HTH.

How can I remove the initial return when the multiple texts are added to the field?

I am asking the user to select a txt file from a specified folder on a server [This is in PowerPoint 2007], but I need to give them the option of selecting more than one, so I have a bit of conditional code to determine this.
One file selected uses this code:
oShape.TextFrame.TextRange.Text = Text
More than one file selected currently uses this:
oShape.TextFrame.TextRange.Text = oShape.TextFrame.TextRange.Text & vbCrLf & vbCrLf & Text
…but this results in an extra return space above it all in the field, which is a bit untidy.
Could anyone advise me on how I can modify this to only get the returns in between the two texts, but not at the beginning?
I am not entirely sure I got the problem, but I believe this will do:
oShape.TextFrame.TextRange.Text = iif(oShape.TextFrame.TextRange.Text <> "", oShape.TextFrame.TextRange.Text & vbCrLf & vbCrLf, "") & Text