Finding attachments with dav queries using AdvancedSearchMethod - vba

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"

Related

VB.net SQL output loop rename file error on next loop

new to the stack here. I am developing some tools for work that allow us to pull information from a database and then operate on it with additional custom code. Since I need the output to not have a header, I want to have one file (as defined by schema.ini) that I will temporarily write the data into then copy and rename it before starting again. Using VS2017, when I debug it spits out the error that it cannot find RawC.txt after the first iteration. I cannot seem to figure out why. It is probably something simple but I have been unable to locate online. Can anyone help me out here? Below is the block I am having trouble with:
For each of the three files, output the sorted list. Schema has the correct format
For index = 0 To 2
If index = 0 Then
whicharr = arrSt(1)
ElseIf index = 1 Then
whicharr = arrSe(1)
ElseIf index = 2 Then
whicharr = arrVi(1)
End If
stopFile = "SELECT " & complist(index) & " INTO [Text;Database=" & TMPath & "].[RawC.txt] FROM [" & whicharr & "] ORDER BY " & complist(index)
cmd = New OleDbCommand(stopFile, conn)
cmd.ExecuteNonQuery()
'Now Copy and rename this file
My.Computer.FileSystem.CopyFile(TMPath & "\RawC.txt", TMPath & "\" & whicharr & ".txt")
'And delete the old RawC.txt file
My.Computer.FileSystem.DeleteFile(TMPath & "\RawC.txt")
Next
The final output from this loop should be three unique files that I will pass to another code that will perform some math on it.

Custom function in Excel for cell hyperlink creation

For example, if i have a complex functions like this one: =IFERROR(CELL("address",INDEX(D:D,MATCH(A2;D3:D$750;0)+ROW(A2);1;1));"") i want to convert it into hyperlink which points to cell returned by that formula. And yeah, i know that it could be done by wrapping it with =HYPERLINK("[file_name.xlsm]" & %formula%) BUT, first of all, it looks very ugly and uncomfortable to read in the big sparse data, and second - it is very inconvenient to copy such data-blocks between Excel instances (and then replace filename).
So i wonder - is it possible to convert such output into cell-link for current file and sheet with readable text like "D156" in place of "[long_file_name.xlsm]$D$156"?
P.S. obviously i can make a custom function which returns current filename and put same formula into second argument of HYPERLINK func, but obviously it will be counter-effective, especially when i have huge chunks of data. So i want to wrap all this into 1 function...
P.P.S. Don't sure if this will be appropriate (it's kinda offtopic for this question), but it will be fine if the same functionality could be done with macro instead of custom function. So the macro should find all the duplicates inside of currently selected range and make hyperlinks (in cell with same offset on different sheet with offset +1, the next sheet after currently active) to next occurrence of every duplicate. The rest i can manage by myself.
UPD1:
Getting filename is not a problem, as i said in P.S., i can write a function like this:
Function GetCurFilename()
GetCurFilename= "[" & ActiveWorkbook.Name & "]"
End Function
but i still need somehow to send part of the first HYPERLINK's argument as second one!
UPD2:
I guess it should be done like this:
Function MakeLinkArgs(cAdrs) As SomeType_interpreted_as_2_arguments
If (cAdrs = "") Then
MakeLinkArgs(1) = ""
MakeLinkArgs(2) = ""
Else
MakeLinkArgs(1) = "[" & ActiveWorkbook.Name & "]" & cAdrs
MakeLinkArgs(2) = Replace(cAdrs, "$", "")
End If
End Function
So this func could be used like this: =HYPERLINK( MakeLinkArgs( IFERROR(CELL("address",INDEX(D:D,MATCH(A2;D3:D$750;0)+ROW(A2);1;1));"") ) )
But still no luck finding type which could be interpreted as 2 arguments (don't sure if such exists at all)...
Not totally sure what you are asking, but I think that =CELL("filename") will help you. This returns both the filename and the sheet. Just extract the sheet name and file name from what this returns. Also portable for cut/paste to other workbooks/worksheets.
Well, i didn't found a way to send multiple arguments with single result from other function, but i found a side way to do what i want. It looks like a dirty hack to me, but i don't sure, maybe it's the way to do things in Excel VBA...
So first it's needed to add a public variable at the top of the Module:
Public sBuff As String
Next, these 2 functions should be added after public var declaration:
Function MakeCLink(cAdrs)
If (cAdrs = "") Then
MakeCLink = ""
sBuff = ""
Else
MakeCLink = "[" & ActiveWorkbook.Name & "]" & cAdrs
sBuff = Replace(cAdrs, "$", "")
End If
End Function
Function sBuf() As String
sBuf = "" & sBuff
End Function
And after compilation it could be used in formulas as such: =HYPERLINK( MakeCLink(IFERROR(CELL("address",INDEX(D:D,MATCH(A2,D3:D$750,0)+ROW(A2),1,1)),"")), sBuf() )
Yes, it's ugly, but works as magic for me =)

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

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.

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

Can't Go To Specific Record on Continuous Form in MS Access

Searched and searched and cannot find a solution to this. I have a form with many continuous form subforms. When I change a value in, lets say FIELD_A on one of the subforms, I run calculations on several other subforms, then the focus returns to FIELD_A. However, during the calculations an update to the PARENT form happens, and needs to happen. So, when I return focus to the original subform, the first record on my subform has the focus. I need to then go to the record I was working on.
I've tried several options, but nothing works. However, if I set a DEBUG breakpoint at the line in the code where it moves to the specified record, then physically RUN the code from that line, it works! I've tried setting a wait period in there to no avail.
Here's a snippet of the code:
Call common.CalculateAllLoadTotals _
(Me, Me.AffiliateID, Me.ClientID, Me.FacilityID, Me.ProposalRevision)
Me.Recordset.FindFirst "[AffiliateID] = '" & Me.AffiliateID & "'" & _
" AND [ClientID] = " & Me.ClientID & _
" AND [FacilityID] = " & Me.FacilityID & _
" AND [ProposalRevision] = " & Me.ProposalRevision & _
" AND [EquipmentID] = " & currItemID
I also tried this:
dim currRecord as Long
currRecord = Me.CurrentRecord
' >>> REST OF CODE HERE <<<
Call common.CalculateAllLoadTotals _
(Me, Me.AffiliateID, Me.ClientID, Me.FacilityID, Me.ProposalRevision)
Me.Form.Recordset.Move = currRecord
As I said, the code works (either one) IF I pause it with a debug then continue executing. Strange.
Sorry that's will not be a complete answer but it is quite lot for a comment.
Regarding your first solution - I'd advise you to try Me.Recordset.Requery
to refresh current record in the main form without moving position.
Regarding you 2nd option - I'd advise to have a look at bookmarks - before update remember bookmark, make some calculations and then move position to the saved bookmark. Something like this -
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
rs.FindFirst "[MyPK]=" & Me!cmbFindByPK
If Not rs.NoMatch Then
If Me.Dirty Then
Me.Dirty = False
End If
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
taken from here Why clone an MS-Access recordset?
I suspect you are updating the recordset underlying the parent form. This causes the parent form to automatically requery, hence the subform position returning to the first record.
The solution is to update the controls on the parent form instead:
Me.Parent!Controlname = XXXX