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

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

Related

How to format textbox field in Access form to show data the same as in imported file to the table

I have a textbox, which is presenting data from one field in selected recordset. This field contains comments made by user in Excel file, which is later imported to Access table. Each comment is made in separete line and in each it looks ok. Textbox present it as one line, but when I export it to Excel again it looks ok in that new excel.
I have tried changing textbox into rich text format. I have also create other textbox, in which I am able to insert comments and then it looks good.
Textbox source code:
sSql = SELECT LogID, 1Comment, 2Comment, Author
sSql = sSql & " FROM tblGeneralLog"
sSql = sSql & " WHERE LogID= " & Me.ID &
Forms![frmMain_CommentAdd]![txtboxComment2].Value = CurrentDb.OpenRecordset(sSql).Fields(2).Value
Probably, in Excel you don't have a "full new line" (CR + LF). Thus, try:
Forms![frmMain_CommentAdd]![txtboxComment2].Value = Replace(CurrentDb.OpenRecordset(sSql).Fields(2).Value, vbCr, vbCrLf)
or:
Forms![frmMain_CommentAdd]![txtboxComment2].Value = Replace(CurrentDb.OpenRecordset(sSql).Fields(2).Value, vbLf, vbCrLf)

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"

AppendText won't append to the next line in a text file / vb

I'm making a program that lets you add student info to an existing CSV text file but whenever I use append text it adds the new info to part of the last line and then a new line.
I want it to do this:
John Doe,29,Male
John Doe,29,Male
It does this instead:
John Doe,29,MaleJo
hn Doe,29,Male
Note: there isn't actually an empty line between each set of info, I just wanted it to be easy to read when I posted it here.
Here is the code for that section:
Dim swVar As IO.StreamWriter = IO.File.AppendText(frmMain.fileName)
swVar.WriteLine(txtName.Text & "," & txtAge.Text & "," & gender)
swVar.Close()
Any help would be appreciated, thanks!
A handy tool in VS2010 (and others) is snippets - right click Insert Snippets... - lots of code patterns for typical tasks. In your case here is a modified snippet:
Sub AddToFile(textToAdd As String, filePath As String)
My.Computer.FileSystem.WriteAllText(filePath, textToAdd, True)
End Sub
You may want to check/add a vbNewLine to the text being added since one is not automatically added as with WriteLine.
Not a direct reply to your stated problem, but an alternate method.
See if something like this works better:
IO.File.AppendText(frmMain.fileName, vbNewLine & txtName.Text & "," & txtAge.Text & "," & gender & vbNewLine)
AppendText will open write and close all in one operation so there's no need for a separate streamwriter. It also doesn't add newlines so those must be added separately
Unless of course you are doing a series of writes to the same file then something like this would probably be more appropriate:
Dim swVar As New IO.StreamWriter(frmMain.fileName, True)
'write your lines here
swVar.WriteLine(txtName.Text & "," & txtAge.Text & "," & gender)
swVar.Close()

Multilines In Richtextbox

Alright, I have a richtextbox that contains this.
line1
line2
As a test I used the code below to confirm that my program can read the lines but it doesn't.
If RichTextBox1.lines.Contains("Line1" & vbcrlf & "Line2") Then
MsgBox("hi")
End If
I've tried vbcrlf, environment.newline, char(32), vbcrlf & _.
thinking that either lines or contains is the problem.
RichTextBox.Lines returns an array with one element for each line of text. Contains("Line1" & VbCrLf & "Line2") will look for an element in the array that matches that string, but your array has one element with "line1" and a second element with "line2", not a single element with both. By the way, "Line1" will not match "line1", as there is a case difference between the two strings.
If you want to read the lines of the RichtTextBox, you can loop through it:
For Each line As String In RichTextBox1.Lines
' Do something here
Next
RichTextBox.Lines Property
have you try this
If RichTextBox1.lines.Contains("Line1" & vblf & "Line2") Then
MsgBox("hi")
End If

Use the actual value of String as a Formatted Value for TextBlock.Text

So basically I have this:
A WPF window with 1 Button (btn_Convert) and 2 TextBoxes (txtBox_StringValue and txtBox_Result).
In txtBox_StringValue I then paste in a formatted string value:
"This is a Header" & vbCrLf & "======================" & _
vbCrLf & "INFO" & vbCrLf & "======================"
Then when I click btn_Convert I would like the following to happen.
Code:
Dim tempStringValue = txtBox_StringValue.Text
txtBox_Results.Text = tempStringValue
However (obviously), when I do the above the Results TextBox just displays the string again:
"This is a Header" & vbCrLf & "======================" & _
vbCrLf & "INFO" & vbCrLf & "======================"
Instead of:
This is a Header
======================
INFO
So how do I get the value of the string and then strip the containing double-quotes so that the value when assigned acts like it was a variable value set in code, not just passing a string.
From the research I have done I am guessing that I need to use Reflection, however I am not familiar with the Reflection concept and don't know how to approach it.
Any help would be greatly appreciated!
Reflection won't help you in this case. It sounds like what you're talking about is dynamically interpreting some VB.NET source code and output the result of executing that code to another text box. In that case you need to use the Code DOM classes to dynamically build an assembly in memory and execute it.